PUG*_*PUG 2 .net c# datatable datagridview readonly
我已将2个数据表列的readonly属性设置为true.
List.Columns[0].ReadOnly = true;
List.Columns[1].ReadOnly = true;
Run Code Online (Sandbox Code Playgroud)
但我只希望它们只在用户尝试更新时才能读取,用户可以向dataGridView添加新行,所以我想在尝试添加新行时将readonly属性设置为false.我尝试在datagrid的CellDoubleClick事件上执行此操作,但它不会做任何事情,因为它是为了调用beginedit迟到.
if(e.RowIndex == GridView.Rows.Count-1)
GridView.Rows[e.RowIndex].Cells[1].ReadOnly = GridView.Rows[e.RowIndex].Cells[0].ReadOnly = false;
else
GridView.Rows[e.RowIndex].Cells[1].ReadOnly = GridView.Rows[e.RowIndex].Cells[0].ReadOnly = true;
Run Code Online (Sandbox Code Playgroud)
有任何想法吗
您必须使用cellbegin编辑将单元格readonly属性设置为true..
private void dataGridView1_CellBeginEdit(object sender,DataGridViewCellCancelEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "ColName0")
{
// you can check whether the read only property of that cell is false or not
}
}
Run Code Online (Sandbox Code Playgroud)
我希望它会帮助你......
| 归档时间: |
|
| 查看次数: |
8579 次 |
| 最近记录: |