winform datagridview 如何设置当首列填写后,其他列才可以填写。

1,主要利用CellBeginEdit来来判断。

  如果首列为 空,则其他列不能编辑。如果首列不为空,其他列才可以编辑。 因为这有涉及到数据车存储

代码如下:

View Code
 1    private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
 2         {
 3             var dgv = (DataGridView)sender;
 4             int columnIndex = e.ColumnIndex;
 5             string firstCellValue =Convert.ToString(dgv[0,e.RowIndex].Value);
 6 
 7             if (columnIndex == 0)
 8             {
 9                 e.Cancel = false;
10             }
11             else
12             {
13                 if (firstCellValue.Equals(string.Empty))
14                 {
15                     e.Cancel = true;
16                 }
17             }
18          
19           
20         }
原文地址:https://www.cnblogs.com/moss_tan_jun/p/2171210.html