摘要
接上一篇GridControl中新增一行的两种方法当在GridControl新增一行后,只有新增行可以更改其他行不可更改。
效果图
代码实现
在GridView的ShowingEditor事件中来判断条件,满足条件就不可编辑,否则可编辑,实现代码片段如下:
private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
{
DataRow row = this.gridView1.GetDataRow(this.gridView1.FocusedRowHandle);
if (row != null)
{
if (String.IsNullOrEmpty(row["id"].ToString())==false&& String.IsNullOrEmpty(row["name"].ToString()) == false)
{
e.Cancel = true;
}
}
}