Combo box in dot net windows application
what difference between SelectedText,SelectedValue and Selected Item in combo box(Dotnet windows application).How to bind value member in combo box?Please help me.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 6, 2010, 12:46 AM EDT
SelectedValue - Gets or sets the value of the member property specified by the ValueMember property. (Inherited from ListControl.)
SelectedItem - Gets or sets currently selected item in the ComboBox.
Sample Code
' Populate the list box using an array as DataSource.
Dim USStates As New ArrayList()
USStates.Add(New USState("Alabama", "AL"))
USStates.Add(New USState("Washington", "WA"))
USStates.Add(New USState("West Virginia", "WV"))
USStates.Add(New USState("Wisconsin", "WI"))
USStates.Add(New USState("Wyoming", "WY"))
ListBox1.DataSource = USStates
' Set the long name as the property to be displayed and the short
' name as the value to be returned when a row is selected. Here
' these are properties; if we were binding to a database table or
' query these could be column names.
ListBox1.DisplayMember = "LongName"
ListBox1.ValueMember = "ShortName"
Gomathi PalaniswamyRank #714 · 3.3K reputationPosted Oct 6, 2010, 12:38 AM EDT
comboBox1.DataSource ="datatable";
comboBox1.DisplayMember="Name";
comboBox1.ValueMember="id";
the name may be same for more than one person so we are using value member to differentiate.
Koteswararao MallisettiRank #2,740 · 511 reputationPosted Oct 6, 2010, 12:44 AM EDT
you give this table as a data source to combobox and it is not display any thing because u must set the data value field and data text field the datavalue field is actual value of that item datatextfield is just displaying purpas
combobox1.DataSource = datatable or dataset
DropDownList1.DataValueField = "eid";
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();
selected value give the datavalufield value where as selected text only give the datatextfield value of that item
and the selected item will give both of them at a time