|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Two values for combo boxHi,
Firstly, I'm using C# if that will make a difference to the answer... Is there any way you can assign two values for a combol box like in the vb6 'old days', so you have say, a string 'UserName' displayed in the combo box, but that returns an integer 'userID' for that selection? If not, what would be the best way to impliment this? An array? I am wanting to use the Datareader, holding two columns of data to populate the combo box. Any ideas would be most appreciated Many thanks in advance Ant Ant,
What you need to do is to create your own class that holds both members - item's diaplay string and item's value then you need to override ToString for that class to return the item's display string. When populate the combobox it will uses ToString to to render the comobox's items. When selection changes you can cast the selected item to your class and read the items value. If you don't have control on the type of the object you load in the combobox or for some other reason you don't want to (or you can't) override ToString you can use combobox's DisplayMemer and ValueMember properties. In this properties set the names of the item type's properties that will provide the display text and the value of the object respectively. Once you do this the combobox will use the DisplayMember to render the items and you can read SelectedValue property to get the value of the selected item. -- Show quoteHide quoteHTH Stoitcho Goutsev (100) "Ant" <A**@discussions.microsoft.com> wrote in message news:700AB71F-FE58-42B1-80DF-F0DF2BED62FE@microsoft.com... > Hi, > > Firstly, I'm using C# if that will make a difference to the answer... > Is there any way you can assign two values for a combol box like in the > vb6 > 'old days', so you have say, a string 'UserName' displayed in the combo > box, > but that returns an integer 'userID' for that selection? > > If not, what would be the best way to impliment this? An array? I am > wanting > to use the Datareader, holding two columns of data to populate the combo > box. > > Any ideas would be most appreciated > Many thanks in advance > Ant
Other interesting topics
Tactics for Debugging Custom Components with CodeDom Serialized State
Auto Complete/Suggest (On Steroids) Newbie User Interface hangs in multi-thread app Project Data Source Using Derived Interface multiple forms/common menu structure ComboBox and Tab character '\t' 'DisplayMember' is not a member of 'System.Windows.Forms.ListView'. code clean up ComboBox: How can I limit user to list items? Generic windows error message |
|||||||||||||||||||||||