I want to drag&drop from treeview to datagrid view. The code for drag is working fine but the code for dropis not working. Please tell me what is the mistake am i doing here???
I couldn’t new values to the dataset.
private void DataGridView1OnDragDrop(object sender, DragEventArgs e)
{
Point dscreen = new Point(e.X, e.Y);
Point dclient = dataGridView1.PointToClient(dscreen);
DataGridView.HitTestInfo hitTest = dataGridView1.HitTest(dclient.X, dclient.Y);
if (hitTest.ColumnIndex == 0 && hitTest.Type == DataGridViewHitTestType.Cell)
{
e.Effect = DragDropEffects.Move;
var ds = (DataSet) dataGridView1.DataSource;
dataGridView1.Rows.Insert(hitTest.RowIndex, "test", "test", "test", "test");
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void getDataGridFromXml()
{
try
{
XmlReader xmlFile;
xmlFile = XmlReader.Create(@"C:\Depth.xml", new XmlReaderSettings());
DataSet ds = new DataSet();
ds.ReadXml(xmlFile);
dataGridView1.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
XMl:
<Product>
<Apple>
<Type>Best</Type>
<Trace>Spain</Trace>
<Quantity>1000</Quantity>
<Description>Notihng</Description>
</Apple>
</Product>
Finally, here is the solution. Just have to define the treenode from drag function and specify the parameters into the datagridview.