Hello,
I have a ComboBox named comboBoxSelChannel.
I declared a structure named MySturct.
public struct MyStruct
{
public int Index;
public string Name;
}
I created a BindingList of MyStruct:
MyStruct myStruct = new MyStruct() ;
BindingList<MyStruct> myList = new BindingList<MyStruct>();
I added 4 MyStruct elements to my BindingList:
myStruct.Name = "Name1" ;
myStruct.Index = 0;
myList.Add( myStruct );
myStruct.Name = "Name2";
myStruct.Index = 1;
myList.Add( myStruct );
myStruct.Name = "Name3";
myStruct.Index = 2;
myList.Add( myStruct );
myStruct.Name = "Name4";
myStruct.Index = 3;
myList.Add( myStruct );
I Binded the ComboBox to the BindingList:
comboBoxSelChannel.DataSource = myList;
comboBoxSelChannel.DisplayMember = "Name";
comboBoxSelChannel.ValueMember = "Index";
The ComboBox is showing 4 elements but instead of showing Name1, Name2,
Name3, Name4 it shows 4 times "MyStruct".
Any Idea why and what I am doing wrong here?
Thanks
Eitan
Morten Wennevik [C# MVP] - 29 Jun 2007 16:55 GMT
> Hello,
>
[quoted text clipped - 41 lines]
> Thanks
> Eitan
Hi Eitan,
You are updating the same struct before adding it again to the list. Try
myStruct = new MyStruct();
myStruct.Name = "Name1" ;
myStruct.Index = 0;
myList.Add( myStruct );
myStruct = new MyStruct();
myStruct.Name = "Name2";
myStruct.Index = 1;
myList.Add( myStruct );
myStruct = new MyStruct();
myStruct.Name = "Name3";
myStruct.Index = 2;
myList.Add( myStruct );
myStruct = new MyStruct();
myStruct.Name = "Name4";
myStruct.Index = 3;
myList.Add( myStruct );

Signature
Happy coding!
Morten Wennevik [C# MVP]