Drag a row from Unbound DataGridView and drop on TreeView

nvalluru

New member
Joined
Aug 23, 2006
Messages
3
Programming Experience
10+
Looking for a sample code to drag a row from unbound DataGridView control and drop on TreeView.DataGridView control is populated from an object
 
vis781-I have tried with all tips mentioned in other thread.When a DataGridViewControl is not bound to DataRowView is empty and there is no source available to copy/move on to target.What's the best way to handle this scenario?Appreciate an immediate response
 
You can check out the Cells collection of a DataGridViewRow (ie. one of the items in the rows collection).
 
John-I don't get your tip.Can you send me a working sample with DataGridView control populated with hard coded values in container form and not bound to data source?
 
The DataGridView has got a Rows property. This Rows property is a collection of DataGridViewRow objects. Each DataGridViewRow object has got a Cells property. This Cells property is a collection of DataGridViewCell objects. The DataGridViewCell has got the Value property for instance. All this is well described with examples in documentation. Also using the code editor with intellisense that always tells you all members of objects and give description of each is good help for programmer in search of knowledge. Example:
VB.NET:
Dim r As DataGridViewRow = DataGridView1.Rows(0)
For Each c As DataGridViewCell In r.Cells
  MsgBox(c.Value)
Next
You would probably send the DataGridViewRow object for dragdrop operation and do something with the values you want to put in TreeView node(s). See the drag and drop windows forms topic in documentation, it is always the same procedure when you do drag and drop in windows forms, the only difference is what object you send and which values to handle on drop. You choose yourself what data you want to send, and you choose how it will be dropped. Online this page is: "Walkthrough: Performing a Drag-and-Drop Operation in Windows Forms" http://msdn2.microsoft.com/en-us/library/za0zx9y0.aspx
 
Back
Top