In my project, combobox values are coming in a method named “getArticles”. Here is the method:
public void getArticles(ComboBox cb)
{
var getAll = getAllFromDB("articles", "", "articleName ASC");
DataTable dt = getAll.Tables["articles"];
cb.DataSource = dt;
cb.DisplayMember = "articleName";
cb.ValueMember = "id";
}
“getAllFromDB” method is doing selection from articles table and returns DataSet. Now my problem is here. When i use cb.SelectedValue i can get id value of article name. This is Ok and good. But when i use cb.SelectedItem it is showing “System.Data.DataRowView”.
Please could you help me, how can i get article name like using cb.selectedItem?
Kind regards.
Try the following codes of lines, may be it will help to get the selected item.
EDIT:
Sorry, the above ComboBoxItem will only works in the case of .Net Framework 4.5, it is in
System.Windows.Controlsnamespace. Refer to following code parts for your answer and check