【问题标题】:RepositoryItemComboBox add specific item for each rowRepositoryItemComboBox 为每一行添加特定项目
【发布时间】:2020-04-27 20:31:21
【问题描述】:
我在 Devexpress GridView 上有一个 RepositoryItemComboBox 控件和 4 行。 RepositoryItemComboBox.Items.Add 影响所有行。在 CustomRowCellEdit 和 CustomRowCellEditForEditing 事件中,我使用 RepositoryItemComboBox.Items.Clear() 和 RepositoryItemComboBox.Items.Add 但它再次影响所有行。我需要修改特定的 RepositoryItemComboBox。例如,RepositoryItemComboBox 的第一行应包含“Michael, John”,RepositoryItemComboBox 的第二行应包含“Sarah, Jake”。
【问题讨论】:
标签:
c#
gridview
devexpress
row
gridcontrol
【解决方案1】:
您可以通过处理CustomRowCellEdit Event 创建一个存储库并根据您的条件分配它。
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" });
}
}