【问题标题】:How to enable editing for new inserted row in a GridView while gridview is allowedit = false?当允许gridview = false时,如何在GridView中启用新插入行的编辑?
【发布时间】:2013-03-10 16:10:26
【问题描述】:

我在表单中有一个 xtraGrid 套件的 GridView 控件。 当我第一次打开表单时,它是 AllowEdit = false。我希望当我按下添加新行链接(由控件内置)以使这唯一的新插入行可编辑。我读到我应该使用 ShowingEditor 事件,但我不知道如何。 到目前为止我写了这个,但这不能编辑该行:

private void gridViewNote_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        {
//this is first tryout  
            //if (gridViewNote.IsNewItemRow(gridViewNote.FocusedRowHandle))// == gridViewNote.GetFocusedDataRow())
            //{
            //    gridColumnStagione.OptionsColumn.AllowEdit = true;
            //}
//second tryout 
            GridView view = sender as GridView;
            SchedeMaterialiDaTaglioDS.SMTAGL_NOTERow currentRow = gridViewNote.GetFocusedDataRow() as SchedeMaterialiDaTaglioDS.SMTAGL_NOTERow;

            SchedeMaterialiDaTaglioDS.SMTAGL_NOTEDataTable changesTable = dsSchMatTaglio.SMTAGL_NOTE.GetChanges() as SchedeMaterialiDaTaglioDS.SMTAGL_NOTEDataTable;
            e.Cancel = !view.IsNewItemRow(view.FocusedRowHandle) &&
                !changesTable.Contains(currentRow);// set.Inserts.Contains(order);

        }

【问题讨论】:

    标签: winforms gridview devexpress xtragrid


    【解决方案1】:

    我希望我能理解你的问题。一些简单的方法:

    1. 将存储库项添加到每个列并处理ShowingEditor 事件,如果应该是只读的,则使用e.Cancel

    2. 弹出一个窗口/文本框,让用户插入值并添加已通过代码插入的值的行。

    3. 使用gridView.CustomRowCellEdit 事件将两个不同的存储库项分配给同一列。像这样:

      RepositoryItemTextEdit rep = new RepositoryItemTextEdit();
      RepositoryItemTextEdit noRep = new RepositoryItemTextEdit();
      noRep.ReadOnly = true;
      
      private void button1_Click(object sender, EventArgs e)
      {
          gridView1.AddNewRow();
          justAddedName = true;
          gridView1.RefreshData();
      }
      
      private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
      {
          if (e.Column == colname)
          {
              if (e.RowHandle == gridView1.RowCount - 1 && justAddedName)
              {
                  e.RepositoryItem = rep;
              }
              else
              {
                  e.RepositoryItem = noRep;
              }
          }
      }
      

    并不完整,只是一个探索的方向。

    希望我能帮上忙。

    【讨论】:

      猜你喜欢
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 1970-01-01
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多