将Datagridview行从一个网格添加到另一个网格 [英] Adding Datagridview rows from one grid to another

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

问题描述

大家好,



我在表格上有两个表格Form1(DGV1)和Form2(DGV2)以及Datagridview控件。



在Form1上有一个指向Form2的按钮链接,用户可以在其中向Form1 datagridview(DGV1)添加行

..在Form2 Datagridview中,第一列中有一个复选框并且用户一次只能选择一行。因此,Form2上有两个按钮1)完成2)添加项目



当用户通过选择单击添加项目时行必须一个接一个地将行添加到Form1上的datagridview中,当单击Done按钮时,应显示Form 1,其中包含添加的所有行。



  int  index = objQM.gvItemDetails.Rows.Add(); 
int Sno = index + 1 ;
string Desc = gvInventory.Rows [RowIndex] .Cells [ 6 ]。Value.ToString ();
int Sellqty = LoadSellQty();
decimal UnitCost = Convert.ToDecimal(gvInventory.Rows [RowIndex] .Cells [ 8 ] .Value.ToString());
decimal Amount = LoadSellQty()* UnitCost;
objQM.gvItemDetails.Rows.Insert(index, false ,Sno,Desc,Sellqty,UnitCost,Amount);





我可以在Form1 datagridview中添加一行,但是当添加第二行时,先前添加的行将丢失。



你能否提出解决方法。



谢谢。

解决方案

< blockquote>



我已经解决了这个问题。

ItemID是网格中的唯一列,用于检查是否添加了其他行。

objQM.gvItemDetails.Rows.Cast < DataGridViewRow > ()。Count(c => c.Cells [7] .EditedFormattedValue.ToString()== ItemID)> 0)

还有一个问题是..假设我通过单击AddItems按钮从Form2向Form1 datagridview添加了一行..然后完成按钮。假设我想通过单击链接添加另一行Form1中的按钮将我带到Form2 ..现在gridview变空并添加了一个全新的行。所以我想知道如何将ROW1添加到Form1 DGV并单击DONE按钮...如果我想要再次添加另一行ROW2.Both Row1和Row2 shud存在但是没有发生。如何实现这一点。


Hi All,

I have two forms Form1(DGV1) and Form2(DGV2) with Datagridview control on both the forms.

On Form1 there is a button link to Form2 where user can add rows to Form1 datagridview(DGV1)
..In Form2 Datagridview there is a checkbox in the first column and the user can select only one row at a time.So there are two button on Form2 1) Done 2) Add Items

When user clicks on Add Items by selecting the rows one after another the rows must be added to the datagridview on Form1 and when Done button is clicked Form 1 should be displayed with all the rows that are added.

int index = objQM.gvItemDetails.Rows.Add();
int Sno = index + 1;
string Desc = gvInventory.Rows[RowIndex].Cells[6].Value.ToString();
int Sellqty = LoadSellQty();
 decimal UnitCost = Convert.ToDecimal(gvInventory.Rows[RowIndex].Cells[8].Value.ToString());
 decimal Amount = LoadSellQty() * UnitCost;
 objQM.gvItemDetails.Rows.Insert(index,false, Sno, Desc, Sellqty, UnitCost, Amount);



I am able to add one row into Form1 datagridview but when the second row is added the row which was added earlier is lost.

Can you please suggest a way to solve this.

Thank you.

解决方案

Hi ,

I have solved the problem.

ItemID is a unique column in the grid so used that to check whether an additional row is added.

objQM.gvItemDetails.Rows.Cast<DataGridViewRow>().Count(c => c.Cells[7].EditedFormattedValue.ToString() == ItemID) > 0)

one more problem is..Suppose I have added a row to the Form1 datagridview from Form2 by clicking AddItems button ..then Done button.Suppose I wanted to add another row by clicking on the link button in Form1 which takes me to Form2..Now the gridview gets empty and a completely new row is added.So i want to know how if ROW1 is added to Form1 DGV and clicked on DONE button...and again if I want to add another row ROW2.Both Row1 and Row2 shud exist but that is not happening.How to achieve this.


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

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