I have uploaded a newer version of the class, this version will resize the treeview to the size of the container automatically at runtime. And also its builder is updated.
Also moe the code I had previpously mentioned to the form as what I haddone was put the UI code into the BizObj.
Click frmCustomer and add set the following codes, respect your codes if any and fit in my codes accordingly:
AfterDelete: THISFORM.cntiIDTreeView.BuildTree()
AfterReQuery: THISFORM.cntiIDTreeView.SynchronizeTreeView()
Save: THISFORM.cntiIDTreeView.BuildTree()
<i><font color="#663300">Hi All,
I have just started with CB seriously. After StepByStep by Ed I went forward to create tree view for the customer form. Do not try this onto the live SbS app by Ed as it still will continue to develop and I don't want that line of thinking to be disturbed becuase it is great in itself as-is. I have picked on the base of SbS just becuase it is all ready and there was no need for me to go into the same basics again.
During the creation, the way I am, I wanted to reuse max. of it also for the parts form. Essentially Customers and Parts form and its tables are not meant for hierarchy, so I added the field iPID Integer with Regular index to the tables.
I added a combo box to the customers form, cboiPID: BoundColumn = 2 BoundTo = .T. ControlSource = v_CustomerMaint.iPID RowSource = SELECT cName, iID FROM Customer ORDER BY cName INTO CURSOR CustomersLK RowSourceType = 3 - SQL Statement ColumnCount = 2 ColumnWidths = 200, 0 Name = cboiPID
Label this combo Parent. The above done try adding the parent codes to a few of the records and check up if it saves well.
As for the "Drag-and-Drop TreeView for CB w/ iIDs" please click on the following link and download the class:
http://venussoftop.tripod.com/Bhavbhuti/Downloads/DnDTvfCBiIDs.zip
Add the class into your project. Drop it onto the Customers form and set the following properties and methods: Name = cntiIDTreeView cBO = THISFORM.aCustomerBizobj cID = iID cParentID = iPID cText = cName cViewName = v_CustomerMaint
Click boCustomer and set the following methods, respect your codes if any and fit in my codes accordingly:
AfterDelete: LPARAMETERS tnRetVal
DODEFAULT(tnRetVal)
THISFORM.cntiIDTreeView.BuildTree()
AfterpointerMove: LPARAMETERS tnfilestatus
DODEFAULT(tnfilestatus)
THISFORM.cntiIDTreeView.SynchronizeTreeView()
Save: LPARAMETERS tlallrows,tlforce
lnRetVal = DODEFAULT(tlallrows, tlforce)
THISFORM.cntiIDTreeView.BuildTree()
RETURN lnRetVal
Thats all, hopefully ;) and you have a working treeview with a min. of efforts. For the pros, is there any way to make the treeview self knowledgable when to BuildTree() or SynchronizeTreeView() on its own, rather than coding in the above methods.
Now here are the catch(es). The ActiveX TreeView and Image Controls used in this class are the ones from VS6 SP5. First you may have to set the Images for Image control, then please do so. Image One will be for groups icon and Image Two will be for singles. I have done rudimentary testing and it's looks okay. If you do run into problems or if you have better ideas or have better and efficient codes, post for this thread. I was not able to change the images in the instance of the class on the form, so if anybody knows about it let me know. I'll try to answer as best as I can with my knowledge.
Hope this class will help newbie like me who want TreeView with least work possible and without going into nitty-gritties and ofcourse utilize OOP to betterment. One of the reason I wanted treeview to be a class reusable was becuase I never came across a reusable treeview, I always noticed that the codes were almost always rewritten completely even if the treeview was used in the same app in two or more different forms. </font></i> Regards Bhavbhuti ©2002 Bhavbhuti Nathwani |