我有一个gridview的行。我希望用户能够抓取一行,并将其移动到winform上的其他几个gridview之一。我怎么能这样做呢?我不熟悉如何实现拖放。如何将gridview行从一个网格拖到另一个网格
这种拖放有什么好的教程?谢谢你的帮助。我有下面的代码(从gridPODetails拖到dataGridView1,它还没有工作,但我更近了(现在我得到了拖动箭头和加号在目的地)我错过了什么?
private void gridPODetails_MouseDown(object sender, MouseEventArgs e)
{
DataGridView.HitTestInfo info = gridPODetails.HitTest(e.X, e.Y);
if (info.RowIndex >= 0)
{
//DataRowView view = (DataRowView)gridPODetails.Rows[info.RowIndex].DataBoundItem; //WRONG
DataRow view = ((DataTable)(gridPODetails.DataSource)).Rows[info.RowIndex]; //RIGHT
if (view != null)
{
gridPODetails.DoDragDrop(view, DragDropEffects.Copy);
}
}
}
private void dataGridView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
DataGridView grid = sender as DataGridView;
DataTable table = grid.DataSource as DataTable;
DataRow row = e.Data.GetData(typeof(DataRow)) as DataRow;
if (row != null && table != null && row.Table != table)
{
table.ImportRow(row);
row.Delete();
}
}
解决:见上面我的编辑我其实是抓住了整个数据表,不只是我想行当然目的只有知道如何与行,而不是整个表格现在,它的工作环境和
!
你的意思是DataGridView? –
@Charles - 是的,我不确定这可能意味着什么? – MAW74656
删除了我的答案。有问题的网格是DevExpress网格。这不是标准的DataGridView。我很遗憾浪费你的时间。 – David