I have created a dataset in my visual studio project which is connected to a Microsoft Acess datebase. I want to populate the values of a particular column in the table into the items of a combo box (i.e. dropdown box). For this I created a table adapter called “empnames” and a method “GetDataByName()” which selects only the column which is required.
First I tried this
comboBox1.ItemsSource = empnames.GetDataByName().ToString();
For this I get the letters in the table name as different items of the combo box. For example if the table name is emp_data, I get 8 items in combobox i.e. ‘e’,’m’,’p’,’d’,’a’,’t’,’a’.
Can you please help me to get proper result.
Thanks
Code:
private void Window_Loaded(object sender, RoutedEventArgs e) {
SampleDataSetTableAdapters.Emp_dataTableAdapter empnames = new SampleDataSetTableAdapters.Emp_dataTableAdapter();
comboBox1.ItemsSource = empnames.GetDataByName();
}
This is the code for method to populate the combobox items. The GetDataByName() is designed using table adapter query configuration wizard. Return type is data table.
You should assign the
DataTableto theItemsSource, and setDisplayMemberPathto the name of the column you want to show.