问题
I have some table from a dataSet in a reportViewer (winform), and some ComboBox. I want the ComboBox's dataSource to be a list of the table column names. How can I do that?
回答1:
Assuming you have a data table in table
variable, then to show list of it's columns in a ComboBox
you can use a code like this:
comboBox1.DataSource = table.Columns.Cast<DataColumn>().ToList();
comboBox1.ValueMember = "ColumnName";
comboBox1.DisplayMember = "ColumnName";
回答2:
you can try this also
comb.DataSource = dt;
comb.ValueMember = dt.Columns[0].ColumnName.ToString();
comb.DisplayMember = dt.Columns[1].ColumnName.ToString();
来源:https://stackoverflow.com/questions/56001568/set-combobox-data-source-as-column-names