RepositoryItemComboBox为每行添加特定的项目。

问题描述 投票:0回答:1

我在Devexpress GridView上有一个RepositoryItemComboBox控件,有4行。RepositoryItemComboBox.Items.Add影响所有行。在CustomRowCellEdit和CustomRowCellEditForEditing事件中,我使用了RepositoryItemComboBox.Items.Clear()和RepositoryItemComboBox.Items.Add,但同样会影响所有的行。我需要修改特定的RepositoryItemComboBox。例如,在RepositoryItemComboBox的第一行应该包含 "Michael, John",第二行应该包含 "Sarah, Jake"。

c# gridview devexpress row gridcontrol
1个回答
1
投票

你可以创建一个存储库,并根据你的条件通过处理 CustomRowCellEdit事件.

    private RepositoryItemComboBox myRepository(string[] myNames)
    {
        RepositoryItemComboBox repositoryItemCombo = new RepositoryItemComboBox();
        repositoryItemCombo.Items.AddRange(myNames);

        return repositoryItemCombo;
    }

那么

    private void GridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
    {
        if (e.Column.FieldName != "YourFieldName")
            return;

        if (e.RowHandle == 1) // Your condition
        {
            e.RepositoryItem = myRepository(new string[] { "Michael", "John" });
        }
        else
        {
            e.RepositoryItem = myRepository(new string[] { "Sarah", "Jake" });
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.