winform 设置devExpress 设置gridControl 指定的例可以编辑,其它的不能编辑核心代码如下
//窗体启动加载时给gridview1注册下面事件,注册代码 gridView1.ShowingEditor += GridView1_ShowingEditor;
private void GridView1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
if (view != null)
{
// 假设我们允许编辑第二列(索引为 1),当列的索引不为1时,不能编辑,下面if语句也可以简写为 e.Cancel = view.FocusedColumn.VisibleIndex != 1;
if (view.FocusedColumn.VisibleIndex != 1)
{
e.Cancel = true;
}
//我们也可以给某例和Tag设置为99,当列的Tag不为99时不能编辑
//if (view.FocusedColumn.Tag?.ToString() != "99")
//{
// e.Cancel = true;
//}
}
}本文来自 www.luofenming.com