ComboBox值为空

时间:2018-02-13 16:51:49

标签: c# winforms combobox

我在System.Windows.Forms.ComboBox中进行选择时会调用下面的代码。我正在写一些调试信息,看看我有什么用。组合框正确显示其内容。 Count是正确的。 SelectedIndex是正确的,即它的值对应于所选的值。但是,SelectedItemSelectedValueSelectedTextText都是空白的。为什么呢?

myComboBox_Contractors.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.bsContractor, "ContractorId", true));
myComboBox_Contractors.SelectedIndexChanged += new System.EventHandler(this.myComboBox_SelectedIndexChanged);
    ...  
        private void myComboBox_SelectedIndexChanged(object sender, System.EventArgs eventArgs)
        {
            var comboBox = sender as System.Windows.Forms.ComboBox;

            System.Diagnostics.Trace.WriteLine("comboBox: " + comboBox.Items.Count);
            System.Diagnostics.Trace.WriteLine("comboBox.SelectedIndex: " + comboBox.SelectedIndex);
            System.Diagnostics.Trace.WriteLine("comboBox.SelectedItem: " + comboBox.SelectedItem.ToString());
            System.Diagnostics.Trace.WriteLine("comboBox.SelectedValue: " + comboBox.SelectedValue.ToString());
            System.Diagnostics.Trace.WriteLine("comboBox.SelectedText: " + comboBox.SelectedText.ToString());
            System.Diagnostics.Trace.WriteLine("comboBox.Text: " + comboBox.Text.ToString());

        }

0 个答案:

没有答案
相关问题