【发布时间】:2013-07-26 19:13:50
【问题描述】:
这是我的一些代码:
List<Targets> _myList = new List<Targets>();
RepositoryItemLookUpEdit MyRepositoryItemLookUpEdit = new RepositoryItemLookUpEdit();
MyRepositoryItemLookUpEdit.DataSource = _myList;
public class Targets
{
public string Target { get; set; }
public bool ShouldDisplay { get; set; }
public Targets(string target)
{
Target = target;
ShouldDisplay = true;
}
}
我的问题:是否有可能在显示下拉列表时只显示带有ShouldDisplay == true 的目标?
注意_myList 可以被事件处理程序访问,所以列表中的项目和它们的ShouldDisplay 属性在运行时被修改。例如:
public void MyGrid_CellValueChanging(object sender, CellValueChangedEventArgs e)
{
if (/* the focused Target item appears more than 3 times in the grid*/)
{
thisTarget.ShouldDisplay = false; // so it will be visually removed from the lookUpEdit and the user cannot select the same one anymore
}
}
顺便说一句,在 CellValueChanging 事件处理程序中分配给 DataSource 是不合适的,因为一旦重新分配 DataSource,用户所做的任何更改都将被丢弃。
【问题讨论】:
-
你为什么要分配 this = new List
();? -
我的回答解决了你的问题吗?
标签: c# winforms gridview user-interface devexpress