Visual Basic Compare Two Treeviews and return differences
Visual Basic 2010 - Compare Two Strings and return differences and matches
VB2010 Compare Strings in Collections |
Collections as an Alternative to Arrays
Although collections are most often used for working with the Object Data Type, you can use a collection to work with any data type. In some circumstances, it can be more efficient to store items in a collection than in an array.
If you need to change the size of an array, you must use the ReDim Statement (Visual Basic). When you do this, Visual Basic creates a new array and releases the previous array for disposal. This takes execution time. Therefore, if the number of items you are working with changes frequently, or you cannot predict the maximum number of items you need, you might obtain better performance using a collection.
A collection, which does not have to create a new object or copy existing elements, can handle resizing in less execution time than an array, which has to use ReDim. But if the size does not change, or changes only rarely, an array is likely to be more efficient. As always, performance is highly dependent on the individual application. It is often worth your time to try both an array and a collection.
A collection, which does not have to create a new object or copy existing elements, can handle resizing in less execution time than an array, which has to use ReDim. But if the size does not change, or changes only rarely, an array is likely to be more efficient. As always, performance is highly dependent on the individual application. It is often worth your time to try both an array and a collection.
This Example
How to compare two Treeviews in VB2010
How to return the differences between two Treeviews
Solution
- Create Visual Basic 2010 Windows Application Project
- On Form1, place two tree views and two textboxes and one button
Visual Basic 2010 Compare Strings from Treeview |
How does it work ?
- Store the Treeview1 [TRV1] nodes into Textbox, and the same with Treeview2 [TRV2]
- How many strings [Lines] in each Textbox
- We want to find where both Textboxes is different and where both Textboxes is match to one another. For example, differences are :
- TRV1 has an extra string [Southern American]- TRV2 node string [Africa] is different from TRV2 node string [African]
Steps to accomplish this task :
Download example from Mediafire
Extended work :
You can easily extract any Database tables, columns Schema into a treeview control, and you can also using this example compare two tables or two columns in a Database using this example as well.
You can use ListViews or ComboBoxes or ListBoxes instead of the Treeview control, I used the treeview control because it's always tricky to work with. Using other controls that store strings in Collection format would be so easy, even much easier than using Treeviews.
Another Treeview Examples
Expand and Collapse two treeviews at the same time according to one another even if they both don't have the same nodes names. Expand TreeView1[TRV1] node when TreeView2 [TRV2] node is expanded or collapsed.
Another Treeview Examples
Expand and Collapse two treeviews at the same time according to one another even if they both don't have the same nodes names. Expand TreeView1[TRV1] node when TreeView2 [TRV2] node is expanded or collapsed.
TreeView Example : Change the node font
TreeView Example : Add a photo (icon) to the TreeView
1) Add ImageList from the ToolBox
2) Add 2 photos to the ImageList1 [From properties, Collection], for example :
- Photo1.Png (Index by default is Zero 0), this will be the Parent icon
- Photo2.Png (Index by default is One 1), this will be the first child icon
3) Code to display image/Icon in the Tree View :
♥ Here are some online Visual Basic lessons and courses :
- Visual Basic .Net snippets collection
- Visual Basic .Net - How to check for the internet connection
- Visual Basic .Net - POP3 and Receiving E-mails
- Visual Basic .Net - Generate Random Combinations
- Visual Basic .Net - Play sounds on Button Click or Mouse Hover
- Visual Basic .Net - Progressbar control
- Visual Basic .Net Solution - The application failed to initialize
- Visual Basic .Net - Working with Database full example
- Visual Basic .Net - There is already an open DataReader associated
- Visual Basic .Net - SyBase Advantage Database [Add, Edit, Search, Delete and DataGridView]
- Visual Basic .Net - Math Functions
- Visual Basic .Net - Communicating with clients [Requirements Docs, Use-Case]
- Visual Basic .Net - Command Prompt Read/Write
- Visual Basic .Net - Crystal Reports 2010 for Visual Basic .Net