내 winforms 응용 프로그램에 ListBox가 있습니다. 나는 '. NET Dictionary Key as ListBox DataSource
Complex databinding accepts as a datasource either in Ilist or IListSource
:
그래서 내가 두 번째 줄에 다음과 같은 오류가있어 다음과 같이 나는 사전의 키 때문에 내가이 데이터 소스로 갖고 싶어 내가하지 않을 두 가지 일을 시도 :IDictionary<Entity1, Entity2> myEntities = new Dictionary<Entity1, Entity2>(); myListBox.DataSource = myEntities.Keys;
myListBox.DataSource = (IList < Entity1>) myEntities.Keys;
Can't convert an object of type 'KeyCollection[Entity1,Entity2]' to type 'System.Collections.Generic.IList`1[Entity1]'.
그리고를 그리고 나는 또한 시도했다 :
myListBox.DataSource = myEntities.Keys.ToList < Entity1>();
하지만 난 myEntities
을 수정할 때, 바인딩을 잃을 그런 식으로, myListBox.DataSource
이 변경되지 않습니다
참고 : 예외 메시지는 나에 의해 번역되므로 정확하게 쓰지 않았을 수 있습니다.
어떻게해야합니까?
감사합니다.
또한 'Complex 데이터 바인딩은 Ilist 또는 IListSource에서 데이터 소스로 받아들입니다.' – Diego
여전히 동일한 예외입니다. – Diego
나는 VS를 해고하고 해결해야했다. .AsEnumerable 또는 .ToList가 필요하면 기억이 안 난다. – IAbstract