将ComboBox数据源设置为列名 [英] Set ComboBox data source as column names

查看:156
本文介绍了将ComboBox数据源设置为列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在reportViewer(winform)中有一个来自dataSet的表,还有一些ComboBox。我希望ComboBox的dataSource是表列名称的列表。我该怎么办?

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?

推荐答案

假设您在变量,然后在 ComboBox 中显示其列的列表,您可以使用如下代码:

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";

这篇关于将ComboBox数据源设置为列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆