如何将选定的行从一个DataGridView移到另一个DataGridView? [英] How do I move selected row from one DataGridView to another DataGridView?

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

问题描述

我有两个具有相同列模式的DataGridView(尽管这两个与DataSource不同的DataView-如果这很重要).将选定行从一个datagridview移到另一datagridview的最佳/最快方法是什么?

注意我使用WPF和C#

谢谢.

I have two DataGridViews that have the same column schema (although two different DataViews as DataSource - if that matters). What is the best/quickest way to move Selected row from one datagridview to the other?

Note I use WPF & C#

Thanks.

推荐答案

我不可以自己移动"一行.您可以在DataGridView的第二个实例中创建一个新行,并以与第一个实例中完全相同的方式填充相同的数据.完成后,从DataGridView的第一个实例中删除该行的第一个实例.

-SA
I don''t you can "move" a row itself. You can create a new row in the second instance of the DataGridView and populate it with exact same data you have put in the first instance in exact same way. When it''s done, remove the first instance of the row from the first instance of DataGridView.

—SA


当您选择要移动的行然后将其设置到DataRow或以这种方式进行操作时:

when you select a row to move then set it into DataRow or do in this way :

foreach (GridViewRow gr in grdMainLeft.Rows)
                {
                    CheckBox chkSelect = (CheckBox)gr.FindControl("chkSelect");
                    if (chkSelect.Checked)
                    {
                        Label lblItemID = (Label)gr.FindControl("lblItemID");
                        string ItemName = gr.Cells[2].Text.Trim();
                        
                        dtGrdMainRight.Rows.Add(lblItemID.Text,ItemName);
                       
                    }
                }


希望对您有帮助.
如果有帮助,请不要忘记将其标记为答案. :)


hope this will help you.
Dont forget to mark as answer if it helps. :)


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

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