winform Combobox出现System.Data.DataRowView的解决的方法

个人总结:

1.触发了SelectedIndexChanged事件时:comboBox1.DataSource = dt;要放在comboBox1.SelectedIndex = 0;的上面

comboBox1.DisplayMember = "hName";
            comboBox1.ValueMember = "hId";
            comboBox1.DataSource = dt;
            comboBox1.SelectedIndex = 0;

2.触发了SelectedValueChanged事件时:comboBox1.DataSource = dt;要放在最上面

comboBox1.DataSource = dt;
            comboBox1.DisplayMember = "hName";
            comboBox1.ValueMember = "hId";
            comboBox1.SelectedIndex = 0;

并且在 comboBox1_SelectedValueChanged事件中还要加上推断。

if (comboBox1.SelectedValue.ToString() == "System.Data.DataRowView") return;
            string selectedHId = comboBox1.SelectedValue.ToString();

上一篇:【转载】jQuery.extend 函数详解


下一篇:ExtJs之Ext.form.field.ComboBox组合框