Re: Adding references to objects in a comboBox

From: zfeld (zfeld100_at_hotmail.com)
Date: 11/29/04


Date: Mon, 29 Nov 2004 12:08:38 -0500

The problem with that, is it will display in the combo box the Tostring() of
MyObj.
The reason that this is a problem is MyObj is a complicated object with many
possible display strings (e.g its name, its author, its publisher, etc.)
The user was going to select vie a radiobutton what he wants to see
displayed in the ComboBox (names, authors, etc.)
I would re-populate the combo box with strings (MyObj.Name, MyObj.Author )
based on his choice but still have a reference to the underlying object when
one item is selected in the comboBox. I therefore can't let use the
ToString() for how would I know as to what to have the overridden ToString()
return (it might be MyObj.Name, or maybe MyObj.Author etc. )

Any other ideas?

"e-lores" <e_lores77QUITARESTO@yahoo.es> wrote in message
news:OpupuOj1EHA.2180@TK2MSFTNGP10.phx.gbl...
> MyObj obj = new MyObj();
> ComboBox cb = new ComboBox();
> cb.Add(obj);
>
> obj is a reference to your object.
>
> You can get it as:
>
> MyObj obj = (MyObj) cb.Item(index);
>
> I hope this help you.
> Bye.
> Ernesto Lores
>
>
>
> "zfeld" <zfeld100@hotmail.com> escribió en el mensaje
> news:umgXB%23i1EHA.2196@TK2MSFTNGP14.phx.gbl...
>> How do I add objects to a comboBox?
>> What I need is something similar to what there was in MFC as
>>
>> MyObj obj;
>> ComboBox cb;
>>
>> int index = cb.Add(obj.name);
>> cb.AddItemData(&obj, index);
>>
>> Which can then be retrieved as:
>>
>> int selectedIndex = cb.GetSelectedIndex();
>> MyObj selctedObj = reinterpret_cast<MyObj
>>(cb.GetItemData(selectedIndex ));
>>
>> Is there any way to store a reference to the object in a C# ComboBox?
>>
>>
>
>