【问题标题】:Set value for same cell in "DevExpress XtraGrid CellValueChanging" event在“DevExpress XtraGrid CellValueChanging”事件中为同一单元格设置值
【发布时间】:2012-02-07 13:09:39
【问题描述】:

我有一个带有一个 GridView 的 XtraGrid,其中有一列带有复选框存储库项。现在我正在处理 CellValueChanging 事件,因为我只想允许用户根据对同一行上其他列值的计算来检查或取消选中,因此我需要此事件的 e.RowHandlee.Column,这不能在存储库控件的 EditValueChanging。

现在某处我的计算表明用户无法检查特定单元格,我抛出一个消息框并尝试Me.BandedGridView1.SetRowCellValue(e.RowHandle, e.Column, False),但不幸的是这不会将该单元格的值设置为 false。

我需要在此处和此处执行此操作,只是因为基于其他列值的计算数量庞大,并且我需要设置我正在正确处理其事件的当前单元格的值。

请帮忙。

我使用的是 DevExpress 9.2(没有机会升级到更高版本)

【问题讨论】:

    标签: winforms gridview devexpress


    【解决方案1】:

    您可能希望通过处理 ShowingEditor 事件来阻止更新。

    class TestData
    {
        public TestData(string caption, bool check)
        {
            Caption = caption;
            Check = check;
        }
        public string Caption { get; set; }
        public bool Check { get; set; }
    }
    

    初始化一些测试数据:

    BindingList<TestData> gridDataList = new BindingList<TestData>();
    gridDataList.Add(new TestData("First row", true));
    gridDataList.Add(new TestData("Second row", true));
    gridControl.DataSource = gridDataList;
    

    句柄 ShowingEditor。检查是否允许用户更改复选框。如果没有,请取消活动。

        private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
        {
            GridView view = sender as GridView;
            //  Decision to allow edit using view.FocusedRowHandle and view.FocusedColumn
            if (view.FocusedColumn.FieldName == "Check")
            {
                //  Allow edit of odd rows only
                bool allowEdit = view.FocusedRowHandle % 2 == 1;
                e.Cancel = !allowEdit;
            }
        }
    

    【讨论】:

      【解决方案2】:

      试试这段代码,它工作得很好!

      private void GridView1_CellValueChanged(object sender, CellValueChangedEventArgs e)
      {
          if (e.Column.Caption != "yourColumnCaption") return;
             GridView1.SetFocusedRowCellValue("yourColumnFieldName", 1);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-10
        • 2012-09-13
        • 2012-09-07
        • 1970-01-01
        • 1970-01-01
        • 2016-09-08
        相关资源
        最近更新 更多