c# - RepositoryItemComboBox 为每一行添加特定项目
问题描述
我在 Devexpress GridView 和 4 行上有一个 RepositoryItemComboBox 控件。RepositoryItemComboBox.Items.Add 影响所有行。在 CustomRowCellEdit 和 CustomRowCellEditForEditing 事件中,我使用 RepositoryItemComboBox.Items.Clear() 和 RepositoryItemComboBox.Items.Add 但它再次影响所有行。我需要修改特定的 RepositoryItemComboBox。例如,RepositoryItemComboBox 的第一行应包含“Michael, John”,RepositoryItemComboBox 的第二行应包含“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" });
}
}
推荐阅读
- c++ - 当 if 仅围绕一个语句时,如何使用 clangs Rewriter 删除 IfStmt,这由预处理器 if 构造决定
- react-native - 如何将状态映射到初始文件(App.js 或 Index.js)上的道具?
- http - 支持 HSTS 的 Http 客户端实现?
- mongodb - 合并来自多个 MongoDB 文档的数组
- python - 无法打开 Spyder
- javascript - 如何使用原生 HTML5 约束 API 验证单选组是否有选择
- android - 尝试从 Room 数据库获取对象后,订阅 LiveData 导致 null
- angular-material2 - 在 Angular Material 2 版本 6 的下拉列表中动态选择一些选项
- r - 将因子日期 1/1/2017 转换为 2017-01
- python - 将多个列表合并为一个嵌套列表