Hi All,

I've form with two controls, one TreeView & one PropertyGrid. The treeview displays the list of equipments. when I select any node from the treeview i.e. any name from the list of equipments, then the property grid will dispaly all the attributes of that selected equipment. The property grid will retrive the selected equipments attributes from a table known as attribute table. Where user can manipulate the attributes. There is a button control named "SAVE". when user clicks on the "SAVE" button the manipulated attribute will be stored into the table.

I can able to find any solution how to link the treeview, propertygrid & database.

Can anybody plz help me.

I m trying it in VB.Net & SQL Server2005.

Thanks & Regards

Hi there,

It's too much to explain in one message, but I'll give you some hints, so you know what to search for.

filling a treeview or list/combo box :

treeview is good for nested objects with parent-child relations or when you want to display different types of objects using a branch for each type. A list or combo control is easier if you have just that one list of records.

Either way you could start by executing an SQL query into a datatable, this requires some knowledge about SQL and using a data adapter, dataset and datatable. I usually make queries with only two fields : ID and NAME. Oftenly the NAME field is a concat of different fields in the actual record. I create the NAME field as I want to display it in the list. This way you can just set the retrieved datatable as datasource for a list or combo, setting the valuemember property to ID and the displaymember property to NAME.

If you use a treeview, you'll have to loop over all datarows in the datatable, creating treenodes with the text property set to NAME and the TAG property set to ID. When selecting a node you'll find the primary key (ID) in the tag, and you can create a new query to get the attributes of the selected record.

Now for the propertygrid. You'll want to create something like a 'virtual' class that has the attributes you want to edit with the propertygrid. If you hard code a class with the needed properties it works too of course, but in that case you might have to create a lot of classes. I find it easier to create a propertybag using the metadata of the fields in any datarow. I'm not going to explain how this can be done here. There is a very good article on the subject called 'bending the .net propertygrid to your will'. Search on it using any wellknown search engine and you'll find it.

I hope this can be of help


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.