C3 comboBox 不同的显示和值成员,但需要同时访问

C3 comboBox different display and value members but need to access both

我有一个包含多列的数据集,其中包括要显示的文本值和我需要用于过滤另一个组合框的数值。

            MyComboBox.DisplayMember = "Reason";
            MyComboBox.ValueMember = "ReasonID";
            MyComboBox.DataSource = MyDataTable;

我遇到的问题是我需要 ID 的那部分代码,但是我需要文本的另一部分代码。我可以取回 ID,但我不确定值更改时如何访问文本。我尝试了以下

            String test1 = MyComboBox.SelectedValue.ToString();
            String test2 = MyComboBox.SelectedText.ToString();

Test1 是我预期的 ID。但是 test2 是“”,我看不到任何提供显示值而不是所选值的属性。

使用ComboBox.Text Property

string value = MyComboBox.Text;

Text 属性 包含您案例中所选项目的 DisplayMember 值。

关于 ComboBox.SelectedText 来自 MSDN

Gets or sets the text that is selected in the editable portion of a ComboBox.

所以这不是所选项目的文本