我在这里有点困惑我想要一些代码在这里或控制这里是我的要求我有这样的datagridview
现在,当我将 7 添加到总 taka 时,另一个将显示为这样
现在真实场景当我将值 3 添加到总 taka 然后在第二个 gridview 中它应该像这样显示
Srno Meters
1 null
2 null
3 null
应该重复向第一个 datagridview 添加新行我将如何实现这一点?
您可以尝试将代码添加到CellEndEdit
事件处理程序,然后您可以将已创建的隐藏显示DataGridView
为第二个,或者您也可以DataGridView
即时创建它。由你决定。我更喜欢显示DataGridView
并初始化行数。这是帮助您理解这个想法的代码:
//First you have to layout 2 DataGridViews at design time and set the Visible of the second
//DataGridView to false
//Your dataGridView2 should also have 2 columns added at design time as shown
//in your second picture.
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e){
//Suppose the column with header Total kaka has name TotalKaka
if (dataGridView1.Columns[e.ColumnIndex].Name == "TotalKaka") {
int i;
if (int.TryParse(dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString(), out i))
{
dataGridView2.Rows.Clear();
dataGridView2.Rows.Add(i);
for (int j = 0; j < i; j++)
dataGridView2[0, j].Value = j + 1;
dataGridView2.Show();
dataGridView2.CurrentCell = dataGridView2[1, 0];
dataGridView2.Focus();
}
}
}
//you should have some Submit button to submit the values entered into the second
//dataGridView, we should process something and surely hide the dataGridView2
private void submit_Click(object sender, EventArgs e){
dataGridView2.Hide();
//other code to process your data
//....
}
注意:这回答了您在此问题中的实际要求,我猜您可能还有更多问题,例如如何处理在 dataGridView2 中输入的数据?如何以另一种形式显示 dataGridView2?......这样的问题确实存在,我认为你应该在其他问题中寻求解决方案,不要试图在这个问题中要求解决它们。