如何将gridview行从一个网格拖动到另一个网格 [英] how to drag gridview row from one grid to another

查看:239
本文介绍了如何将gridview行从一个网格拖动到另一个网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有行的gridview。我希望用户能够抓住一行,并将其移动到winform上的其他几个网格视图之一。我该怎么做呢?我不熟悉如何在这里实现拖放。



任何有关这种拖放的好教程?感谢您的帮助。



更新:好的,我有以下代码(从gridPODetails拖到dataGridView1,它还没有工作,但我离我很近获取拖拽箭头和加号在目的地)。我缺少什么?

  private void gridPODetails_MouseDown(object sender,MouseEventArgs e) 
{
DataGridView.HitTestInfo info = gridPODetails.HitTest(eX,eY);

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_Dra gDrop(object sender,DragEventArgs e)
{
DataGridView grid = sender as DataGridView;
DataTable table = grid.DataSource as DataTable;
DataRow row = e.Data.GetData(typeof(DataRow))作为DataRow;

if(row!= null&&& table!= null&& row.Table!= table)
{
table.ImportRow(row);
row.Delete();
}
}

解决方案:查看我上面的编辑。我实际上抓住了整个datatable,而不仅仅是我想要的行。当然,目的地只知道如何使用Rows,而不是整个表。现在它的工作!

解决方案

我发现这个 Bing search 。它看起来像你正在寻找的东西。



http:// tv.devexpress.com/Content/XtraGrid/XtraGridDragRowsBetweenGrids/XtraGridDragRowsBetweenGrids.pdf


I have a gridview with rows. I'd like the user to be able to grab a row, and move it to one of several other gridviews on the winform. How can I go about doing this? I'm not familiar with how to implement drag and drop here.

Any good tutorials on this sort of drag and drop? Thanks for your help.

UPDATE: Ok, I have the following code (to drag from gridPODetails to dataGridView1. Its not working yet, but I"m closer (now I get drag arrow and plus sign in the destination). What am I missing?

 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();
    }
}

SOLVED: See my edit above. I was actually grabbing the entire datatable, not just the row I wanted. Of course the destination only knows how to work with Rows, not entire tables. Now its working!

解决方案

I found this on a Bing search. It looks like exactly what you're looking for.

http://tv.devexpress.com/Content/XtraGrid/XtraGridDragRowsBetweenGrids/XtraGridDragRowsBetweenGrids.pdf

这篇关于如何将gridview行从一个网格拖动到另一个网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆