【问题标题】:object reference not set for DataView from gridivew.DataSource as DataView未从 gridivew.DataSource 为 DataView 设置对象引用作为 DataView
【发布时间】:2020-07-28 05:38:18
【问题描述】:

我有方法验证编辑器来验证重复

private void GridView1_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
        {
            GridView view = sender as GridView;
            DataView currentDataView = view.DataSource as DataView;
            if (view.FocusedColumn.FieldName == "Sequence")
            {
                //check duplicate code  
                string currentCode = e.Value.ToString();
                for (int i = 0; i < currentDataView.Count; i++)
                {
                    if (i != view.GetDataSourceRowIndex(view.FocusedRowHandle))
                    {
                        if (currentDataView[i]["Sequence"].ToString() == currentCode)
                        {
                            e.ErrorText = "Duplicate Code detected.";
                            e.Valid = false;
                            break;
                        }
                    }
                }
            }
        }

但它说没有设置对象引用,问题出在DataView currentDataView = view.DataSource as DataView; 但我不明白为什么。

【问题讨论】:

    标签: winforms gridview dataview gridcontrol devexpress-gridcontrol


    【解决方案1】:

    我正在使用 ado 实体数据集填充我的网格控件。所以在致电adapter.Fill(dataset) 之后。我还要写gridcontrol.DataSource=dataset;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      • 2011-07-04
      • 2010-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多