SWJGComboBox.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.sb_zsxxBindingSource, "nsr_swjg_dm", true));
this.dM_SWJGComboBox.DataSource = this.dM_SWJGBindingSource;
this.dM_SWJGComboBox.DisplayMember = "SWJG_JC";
this.dM_SWJGComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.dM_SWJGComboBox.ValueMember = "SWJG_DM";private void dM_SWJGComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
            this.dataSet1.sb_zsxx.Rows[BindingSource1.Position]["SWJG_MC"] = dM_SWJGComboBox.Text;}以上为代码,奇怪的是下拉列表只能显示第一项,别的项目显示不出来。
而去掉this.dataSet1.sb_zsxx.Rows[BindingSource1.Position][0] = ComboBox1.Text
这句下拉列表就能正常显示,真是太奇怪了,是我的机器有问题,还是这个控件有BUG,还是代码有问题呢?

解决方案 »

  1.   

    参考下面的绑定方式.
    ComboBox1.DataSource = myDataSet ;//数据集
    ComboBox1.DisplayMember = "person.userId" ;//表名加字段名
    ComboBox1.ValueMember = "person.username" ;this.ComboBox1.DataSource = myDataTable;//数据表
    this.ComboBox1.DisplayMember = "Name";//字段名
    this.ComboBox1.ValueMember = "userId";//字段名
      

  2.   

    this.dataSet1.sb_zsxx.Rows[BindingSource1.Position]["SWJG_MC"] = dM_SWJGComboBox.Text;
    去掉这句执行正常,加上就不正常。
      

  3.   

    //也许是这样
    this.dataSet1.sb_zsxx.Rows[BindingSource1.Position]["SWJG_MC"] = dM_SWJGComboBox.SelectedItem.ToString();
      

  4.   

    //也许是这样
    this.dataSet1.sb_zsxx.Rows[BindingSource1.Position]["SWJG_MC"] = dM_SWJGComboBox.SelectedItem.ToString();
    这样写也是如此。
    =================================================================================
    SWJGComboBox.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.sb_zsxxBindingSource, "nsr_swjg_dm", true)); this.dataSet1.sb_zsxx.Rows[BindingSource1.Position]["SWJG_MC"] = dM_SWJGComboBox.Text;
    与这两个有关系,是不是在这个事件中不能设置combobox已经通过简单绑定的表的其它字段的内容呢?