这是我的一些代码:
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,用户所做的任何更改都将被丢弃。