在datagrid中使特定单元格可编辑 [英] Make a particular cell editable in datagrid
问题描述
大家好
我有一个带有一个复选框列的数据网格和3个数据列
现在我想要像哪个复选框我检查然后在特定列的单元格上的那一行应该是可编辑的
例如我的数据网格是这样的
Hi all
I have a datagrid with one check box column and 3 data columns
now i want like which ever check box i check then in that row on cell of a particular column should be editable
e.g. my datagrid is like this
check name group value
checkbox aaa A 5
checkbox bbb B 10
现在,如果我选中第一个复选框,那么只有值为5的单元格应该是可编辑的。取消选中它将是非可编辑。
请告诉我怎么做..
So now if i check the first check box then only the cell with value 5 should be editable.and in uncheck it will be non-editable.
Please tell me how to do this..
推荐答案
check name group value
checkbox aaa A 5
checkbox bbb B 10
有两种方法可以完成你的任务....
1)只需在数据gridview的chekbox检查事件上写...
there are two way to accomplish your task that is....
1) just write on the chekbox checked event of the data gridview ...
DataGridView1.Row([rowinedx]).Cell([cellindex]).ReadOnly=True
2)秒检查复选框已选中或不在datagridview的CellClick事件上
并写相同的
2) second is check for checkbox is checked or not on CellClick event of datagridview
and write same
DataGridView1.Row([rowinedx]).Cell([cellindex]).ReadOnly=True
一切顺利.......... .....
All the best...............
嗨
只需将以下代码粘贴到datagridview的CellContentClick事件中
Hi
just paste the following code in the CellContentClick event of the datagridview
'check if the clicked column is the right one
If e.ColumnIndex = 0 Then
'change cell readonly property according to checkbox state
DataGridView1.Rows(e.RowIndex).Cells(3).ReadOnly = Not _ DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
End If
这篇关于在datagrid中使特定单元格可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!