1

I'm brand new to WPF. I have a combo box that I want to fill with the names of the columns of a database. I have seen from other posts that

select *

from MyDatabaseName.information_schema.columns

order by table_name, ordinal_position

will give you the names of the table, but how do I then add each element to the combo box?

Community
  • 1
  • 1

2 Answers2

1

Set the ItemsSource of your ComboBox. Of course, how you are going to set is your choice. Some are more recommended than others. However, one simple choice is to directly set it in code.

Assuming that cb is the name of your ComboBox and yourlist is the name of your list, use ``cb.ItemsSource = yourlist;

There are other choices such as Binding the ItemsSource too. See this post or Google it.

Community
  • 1
  • 1
rmojab63
  • 3,513
  • 1
  • 15
  • 28
1

Set the ItemsSource of your ComboBox

And Set DisplayMemberpath in XAML

<ComboBox DisplayMemberPath="PropertyName"/>
Ragavan
  • 2,984
  • 5
  • 22
  • 24