我想从树视图拖放到数据网格视图。的代码drag
工作正常,但代码drop
不工作。请告诉我我在这里做错了什么???
我无法为数据集添加新值。
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>