How do I allow edit only a particular column in datagridview in windows application?

后端 未结 3 735
攒了一身酷
攒了一身酷 2020-12-09 01:38

I want to enable only two columns in the DataGridview to be able to edit. The others should not be allowed to edit. Further I am not directly linking to datasource; I will b

相关标签:
3条回答
  • 2020-12-09 02:30
    foreach (DataGridViewColumn dc in dataGridViewX1.Columns)
    {
           if (dc.Index.Equals(0) || dc.Index.Equals(1))
           {
               dc.ReadOnly = false;
           }
           else
           {
                dc.ReadOnly = true;
           }
     }
    
    0 讨论(0)
  • 2020-12-09 02:38

    Set the ReadOnly property of the other columns to true.

    (You'll probably need to loop through the Columns collection and use an if statement)

    0 讨论(0)
  • 2020-12-09 02:39
    dataGridView1.ReadOnly = false;
    dataGridView1.Columns[1].ReadOnly = true;
    dataGridView1.Columns[2].ReadOnly = true;
    

    here first column (index 0) will be editable.

    0 讨论(0)
提交回复
热议问题