DevExpress表格控件的单元格设置自定义编辑器

GridView示例:

    RepositoryItem emptyRepositoryItem = new RepositoryItem();
    RepositoryItemCheckEdit checkEdit = new RepositoryItemCheckEdit();
    RepositoryItemTextEdit textEdit = new RepositoryItemTextEdit();
    RepositoryItemComboBox repositoryItemComboBox = new RepositoryItemComboBox();

    private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
    {
        var gridView = sender as GridView;
        if (e?.Column?.Name == "checkEdit")
        {
            e.RepositoryItem = e.RowHandle % 2 == 1 ? checkEdit : emptyRepositoryItem;
        }
        else if (e?.Column?.Name == "textEdit")
        {
            e.RepositoryItem = gridView.RowCount - 6 == e.RowHandle || e.RowHandle == 1 ? textEdit : emptyRepositoryItem;
        }
        else if (e?.Column?.Name == "repositoryItemComboBox")
        {
            e.RepositoryItem = e.RowHandle == gridView.RowCount - 1 || e.RowHandle == 0 || e.RowHandle % 2 != 0
                ? emptyRepositoryItem
                : repositoryItemComboBox;
        }
    }
  • DevExpress中的表格控件(GridControl、TreeList、Gantt、spreadsheet),理论上都可通过类似CustomRowCellEdit事件(Treelist用的是CustomNodeCellEdit事件),为每一个单元格设置独有的编辑控件类型。
posted @ 2022-11-30 16:22  北有高楼233  阅读(499)  评论(0)    收藏  举报