在 DataGridView 中,添加新行时将列的 ReadOnly 属性设置为 false,更新其 true (c#.net)
我已将 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;
任何想法
I have set the readonly property of 2 datatable columns to true.
List.Columns[0].ReadOnly = true;
List.Columns[1].ReadOnly = true;
But i only want them to be read only when user is trying to update, User can add new rows to dataGridView so i want to turn the readonly property to false when trying to add new row. i tried doing this on CellDoubleClick event of the datagrid but it wont do anything as it is to late for the beginedit to be called.
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;
Any ideas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须使用 cellbegin 编辑将单元格只读属性设置为 true。 。
我希望它能帮助你...
you Have to use the cellbegin edit to make the cell readonly property to true. .
I hope it will helps you...
听起来您想要做的是将网格中的所有行设为只读,除非它们是新行,这意味着无法编辑创建的行。如果这是正确的,那么您可以做的就是在 DataBindingComplete 事件期间将该行设置为只读,如下所示:
重要的部分是检查该行是否是新行。
It sounds like what you want to do is make all the rows in the grid readonly unless they are the new row, thus meaning created rows cannot be edited. If that is correct then what you can do is set the row to readonly during the DataBindingComplete event like so:
The important part is the check to see if the row is the new row.