![](/img/trans.png)
[英]How can I pass multiple cell values of datagridview from one form to another at same time in C#?
[英]Pass data from one form to a specific cell in a datagridview from another form in C#
我有一个数据网格视图dgv1,它有5列,分别是:贷方,借方,EntryDescription,AccountingEntry,Employee。 由于在EntryDescription中我可能必须输入几行文本,所以我做了一个事件,其中,当单击EntryDescription时,带有Richtextbox的新窗体将显示为ShowDialog,并且一旦编写完说明,用户就按AddDescription按钮和任何在richtextbox中输入的文本都应添加到dgv1的当前行和EntryDescription单元格中。 我已经创建了一些代码,但是不知道继续其余代码。 我需要你的智慧。 谢谢。
我知道单击EntryDescription会出现一个下拉文本框,在其中放置描述是一种更好的方法,但是我不知道该怎么做,所以我就此解决了。
在AccountingEntry表格中
public static int RowCount { get; set; }
public static string DescriptionToAdd { get; set; }
private void dgv1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex != EntryDescription.Index) return;
var bal = new AddAccountingEntryDescription
{
RowIndex = dgv1.CurrentCell.RowIndex
};
bal.ShowDialog();
}
在AddAccountingEntryDescription表单中
public int RowIndex { get; set; }
private void btnAdd_Click(object sender, EventArgs e)
{
AccountingEntry.RowCount = RowIndex;
AccountingEntry.DescriptionToAdd = txtDescriptionToAdd.Text;
}
这很简单。 文本输入表单不必了解有关网格的任何信息,甚至不必了解其他表单。 它所要做的就是通过公共属性公开数据。 ShowDialog
返回后,原始表单从该属性获取数据,并对其执行任何操作。 如果要将该文本放入网格中的单元格中,则可以像其他时间一样进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.