gpt4 book ai didi

c# - 在 DataGridView 中,在添加新行时将列的 ReadOnly 属性设置为 false,更新其 true (c#.net)

转载 作者:行者123 更新时间:2023-11-30 19:46:49 24 4
gpt4 key购买 nike

我已将 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 编辑来使单元格只读属性为真。 .

   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

}
}

希望对你有帮助...

关于c# - 在 DataGridView 中,在添加新行时将列的 ReadOnly 属性设置为 false,更新其 true (c#.net),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7824813/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com