我在Devexpress GridView上有一个RepositoryItemComboBox控件,有4行。RepositoryItemComboBox.Items.Add影响所有行。在CustomRowCellEdit和CustomRowCellEditForEditing事件中,我使用了RepositoryItemComboBox.Items.Clear()和RepositoryItemComboBox.Items.Add,但同样会影响所有的行。我需要修改特定的RepositoryItemComboBox。例如,在RepositoryItemComboBox的第一行应该包含 "Michael, John",第二行应该包含 "Sarah, Jake"。
你可以创建一个存储库,并根据你的条件通过处理 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" });
}
}