Skip to main content
 首页 » 编程设计

c#之组合框未绑定(bind)

2024年02月13日15虾米哥

我正在尝试通过数据集列绑定(bind)组合框。

我有以下数据集:

我想通过 LocationName 列绑定(bind)组合框。

我正在为此使用以下代码:

cmbLocation.DataBindings.Add(New Binding("Text", dsLocations, "LocationName")) 

但它抛出以下错误:

Cannot bind to the property or column LocationName on the DataSource. Parameter name: dataMember

请帮帮我。

请您参考如下方法:

尝试将 ComboBox 绑定(bind)到数据源:

cmbLocation.DisplayMember = "LocationName"; 
cmbLocation.ValueMember = "LocationName"; 
cmbLocation.DataSource = dsLocations; 

它更容易,IMO 更具可读性。