View previous topic :: View next topic |
Author |
Message |
martok13
Joined: 02 Sep 2005 Posts: 1
|
Posted: Fri Sep 02, 2005 6:21 pm Post subject: How to add Row |
|
|
Hi,
im trying to add a row to my virtual tree, but im running into a road block.
from what i can tell it has to link to a dataset, and i dont want this feature.
i just want to add my own rows with there own children, something like the listview that is build into visual studio. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Sep 03, 2005 4:49 am Post subject: |
|
|
Virtual Tree's programming model is a bit different to the standard .NET tee and list view. It is fully data bound - which means that you don't add visual display elements (such as rows or nodes) yourself. Instead you provide it with a data source (such as a list of objects) and it builds the visual display.
You use RowBindings to tell VirtualTree how to map the object properties to the display elements. The advantage of this approach is that VirtualTree handles all the mapping between user interface elements and you domain objects which otherwise you have to manage yourself. It also allows Virtual Tree to be very quick and resource efficient - because it only creates the user interface elements (rows) it needs to display the current data. With a standard TreeView or ListView you have to create the nodes or rows upfront. For a very large data source this can take a long time and consume a great deal of memory.
So to get back to the original question. You don't create a row. Instead you create a list of objects that you want to display. For instance you can create an ArrayList of FileInfo objects and set this as the data source for your tree. You use the VirtualTree designer (right click on the control) to auto-generate RowBindings for the FileInfo objects. This automatically creates Columns for each of the public properties of the FileInfo class and CellBindings which map the properties to columns (see the FileBrowser sample).
To add a new row you simple add another object to the ArrayList and tell VirtualTree to update its display by calling UpdateRows. ArrayList does not support the IBindingList interface which notifies clients of changes to a collection - so you have to call UpdateRows yourself. If your DataSource supports IBindingList (as DataSets do for instance) then you simply add your new object to the collection and Virtual Tree will be notified automatically and update the display.
Let us know if this answers your question. _________________ Infralution Support |
|
Back to top |
|
|
|