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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manikavelu VelayuthamPosted Oct 6, 2010, 4:46 AM
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"
Koteswararao MallisettiPosted Oct 6, 2010, 4:44 AM
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
Gomathi PalaniswamyPosted Oct 6, 2010, 4:38 AM
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.