我已将 2 个数据表列的只读属性设置为 true。
List.Columns[0].ReadOnly = true;
List.Columns[1].ReadOnly = true;
但我只希望它们仅在用户尝试更新时只读,用户可以向 dataGridView 添加新行,因此我想在尝试添加新行时将 readonly 属性设置为 false。我尝试在数据网格的 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;
有任何想法吗
您必须使用 cellbegin 编辑将单元格只读属性设置为 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
}
}
我希望它能帮助你...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)