[英]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.