1. 程式人生 > 其它 >DevExpress表格控制元件的單元格設定自定義編輯器

DevExpress表格控制元件的單元格設定自定義編輯器

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事件每一個單元格設定獨有的編輯控制元件型別,可以根據具體的需求調整。