C# 绑定时未排序的已排序列表
我有一份分类清单。当我将它绑定到列表框时,它不会以有序的方式显示该项C# 绑定时未排序的已排序列表,c#,data-binding,list,C#,Data Binding,List,我有一份分类清单。当我将它绑定到列表框时,它不会以有序的方式显示该项 territoryListBox.BeginUpdate(); this.Text = ((INamedEntity)_currentList[0]).Name; territoryListBox.DataSource = _currentList; territoryListBox.DisplayMember = "Name"; territoryListBox.Sorted = true; territoryListBox
territoryListBox.BeginUpdate();
this.Text = ((INamedEntity)_currentList[0]).Name;
territoryListBox.DataSource = _currentList;
territoryListBox.DisplayMember = "Name";
territoryListBox.Sorted = true;
territoryListBox.EndUpdate();
例如,列表中的第一项是A。该文本显示“A”,这是列表中的第一项。但列表框显示:
B
C
A
_currentList是一个IList您是否接受异常?当我尝试此操作时(设置
排序时
)会出现参数异常
:
设置DataSource属性时,无法修改Items集合
在国际海事组织,首先对列表进行排序,并绑定到该列表;但是,快速测试表明,在设置数据源
之前设置已排序
,同样有效
territoryListBox.Sorted = true;
territoryListBox.DataSource = yourListOfData;
territoryListBox.DisplayMember = "Name";
只是为了好玩,试试看。显然,这是不必要的,但有些事情正在失控。当你说你有一个已排序的列表时,你是说列表在绑定之前已排序,还是说列表可以排序?我的意思是,在绑定之前,列表中的项已按正确的顺序排列。我不会接受任何例外。我不知道你为什么会得到这个例外。我尝试了你的技巧,先对列表进行排序,现在它起作用了。territoryListBox.BeginUpdate();territoryListBox.Sorted=true;territoryListBox.DisplayMember=“Name”;territoryListBox.DataSource=\u currentList;territoryListBox.EndUpdate()_currentList是IList,没有ListBox.Sort方法。