简体   繁体   中英

How to replicate drop-down label and value in C# WinForm

I am new to C# and I am trying to create a drop-down box with a label and value property. For example in HTML I can have <option value"user_name"> Username </option> , how do I get this done in WinForms using C#.

I understand how to create a combo box and add string collections to it using the WinForm designer, but how do I assign value to this strings? The value is quite important, as this is what is needed to interact with a different server.

Thanks.

Break up your problem

1) You said - "I understand how to create a combo box and add string collections to it using the WinForm designer"

2) You said - "but how do I assign value to this strings?"

Option 1, is not at all related to Option 2.

Option 1 - You are adding data to the combobox in design mode.

Option 2 - Which string you are talking about? If you have already assigned the data(collection of strings) to combobox then combobox will display collection of strings only. M i right?

You don't need Option 1, if you are implementing Option 2.

You need data to be displayed in your combobox which your user will select.

So, now where the data coming up? It is from Sql Server/XML/Text File/...? Or you are creating a List/Dictionary in your code and assigning to the combobox?

So finally, you can use any one approach...either Option 1 - "add data to your combobox in design mode" Or Option 2 - "add data to your combobox by retrieving from a datasource(Sql Server/XML/Text File/List/Dictionary)".

How to do that, refer the links mentioned in your comments.

Both the case/s, data will be available inside combobox and user can interact with the data inside combobox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM