all groups > vb.net controls > october 2005 >
You're in the

vb.net controls

group:

Overriding ToString on a UserControl and adding it to a ComboBox


Re: Overriding ToString on a UserControl and adding it to a ComboBox Herfried K. Wagner [MVP]
10/20/2005 12:00:00 AM
vb.net controls:
"Jason Barnett" <jwb@wbai.com> schrieb:
[quoted text, click to view]

I am not able to reproduce this behavior (.NET 1.1).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Overriding ToString on a UserControl and adding it to a ComboBox Jason Barnett
10/20/2005 9:26:04 AM
I'm designing a UserControl that contains a ComboBox and a Panel. I'd like
to swap the control contained in the Panel (a custom "child" usercontrol)
based on the selection in the ComboBox. One way that I thought I might do
this is to override the ToString on the "child" control and add that control
to the ComboBox. Then, on the SelectedIndexChanged event of the ComboBox I
could clear the contents of the Panel and add the SelectedItem.

I've created classes before that don't inherit from anything (except, of
course, Object) and overrode ToString. Then, after adding the object to a
ComboBox, the ToString value was shown in the drop-down list. However, the
ComboBox shows a blank item in its list if the object added is a
UserControl. Does anyone have any ideas why this is happening and how I
might resolve this? I'd appreciate the help.

Re: Overriding ToString on a UserControl and adding it to a ComboBox Jason Barnett
10/20/2005 9:43:36 AM
Based on the information I found in the MSDN Library, I found a solution.
By setting the DisplayMember property of the ComboBox to a property name
that contains the text to be shown, the appropriate text is shown for my
usercontrol.

I'm still confused as to why the ToString method was not used for a
UserControl. If anyone does have an explanation I wouldn't mind hearing it.
In the meantime, I can at least move on.


[quoted text, click to view]

AddThis Social Bookmark Button