错误:复杂DataBinding接受IList或IListSource作为数据源

时间:2016-10-15 06:11:49

标签: c# winforms data-binding combobox

我正试图在医院预约,当患者选择诊所时,应列出所选诊所的医生姓名

我在Project DataSet向导中的TableAdapter中进行查询 当我在Dataset中测试它或者我从ComboBox向导绑定它时,它工作正常 但是当我尝试使用comboBox.DataSource更改comboBox的数据时,我得到了 这个错误:

  

Complex DataBinding接受IList或者数据源作为数据源   IListSource。

这是我的代码:

private void Reservation_Load(object sender, EventArgs e)
{
    // TODO: This line of code loads data into the 'mRMSDataSet.Departments' table. You can move, or remove it, as needed.
    this.departmentsTableAdapter.FillByCLinics(this.mRMSDataSet.Departments);
}

private void clinicNameComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    clinicDoctorsComboBox.DataSource = this.clinicDoctorsTableAdapter.FillByClinicDoctors(this.mRMSDataSet.ClinicDoctors, Convert.ToInt32(clinicNameComboBox.SelectedValue.ToString()));
    clinicNameComboBox.DisplayMember = "empName";
    clinicNameComboBox.ValueMember = "empId";
}

1 个答案:

答案 0 :(得分:1)

错误是自我解释并记录在案。当您为组合框的DataSource属性分配值时,该值未实现IListIListSource接口,您将收到ArgumentException

  

Complex DataBinding接受IList或者数据源作为数据源   IListSource。

在上面的代码中,您将Fill方法(通常为int)的结果分配给DataSource的{​​{1}}。相反,您应首先ComboBox Fill,然后以这种方式将DataTable分配给控件的DataTable

DataSource