我是新来的,但我想问一些事情。我有
我希望在dataGridTwo
中添加一行时自动填充dataGridOne
。在dataGridTwo
数量单元格中,dataGridOne
数量单元格与相同的dataGridOne
运输容器单元格相加。
答案 0 :(得分:1)
您希望处理您的"装运箱中的单元格的CellEndEdit
事件"柱:
dataGridOne.CellEndEdit += DataGridOne_CellEndEdit;
这个想法是每当“运输容器”中的一个单元格时。列已更改,您将遍历计算每个容器的出现次数的所有行。然后,您将使用这些计数更新dataGridTwo
;根据需要添加任何缺少的容器。
不要带走所有的乐趣,代码/算法:
private void DataGridOne_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
// ColumnName = the Name of the Shipping Container Column
if (dataGridOne.Columns[e.ColumnIndex] == dataGridOne.Columns["ColumnName"])
{
Dictionary<string, int> sums = new Dictionary<string, int>();
// For each row that's not the new row in dataGridOne
// key = the value in cell["ColumnName"] of the row (i.e. "Mega Bags")
// if sums contains the key, increment sums value
// else sums value is 1
// For each row that's not the new row in dataGridTwo
// key = the value in cell["ColumnName"] of the row (i.e. "Mega Bags")
// if sums contains the key, set the cell value to sums value
// else set the cell value to 0
// remove the key from sums
// For each remaining KeyValuePair in sums
// add a new row to dataGridTwo using (key, CRIS ID, value)
}
}
答案 1 :(得分:0)
private void cellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
//Only handles cases where the cell contains a TextBox
var editedTextbox = e.EditingElement as TextBox;
if (editedTextbox != null)
{
//your logic of quntity
grid2.rows.add();
grid2.rows[grdi.rowcount-1].cell["Cell Name"].value=qty;
}
}