如何知道当前在组合框弹出窗口中选择了哪个项目

时间:2014-03-25 11:33:57

标签: wpf combobox

如何知道组合框弹出窗口中当前选择的项目。因此,当弹出窗口内的导航时,可以更新组合框。

注意:虽然组合框的弹出窗口仍处于打开状态,但需要更新它。如下图所示,

enter image description here

2 个答案:

答案 0 :(得分:2)

对于ComboBox,请尝试将IsEditable设置为True,如下所示:

<ComboBox IsEditable="True"
          IsReadOnly="True"
          SelectedIndex="0">

    <ComboBoxItem>1</ComboBoxItem>
    <ComboBoxItem>2</ComboBoxItem>
    <ComboBoxItem>3</ComboBoxItem>
</ComboBox>

答案 1 :(得分:-1)

1)添加选择已更改ComboBox的事件处理程序,如

this.comboBoxName.SelectionChanged += new SelectionChangedEventHandler(comboBoxSelection_NOTHROW);

2)事件处理程序方法实现,

private void comboBoxSelection_NOTHROW(object sender, SelectionChangedEventArgs e)
    {
        try
      {
            ///Business logic goes here
               CUSTOMER selectedItem = (sender as ComboBox).SelectedItem as CUSTOMER;
               if (null != selectedUser)
               {
                    comboBoxName.SelectedItem = selectedItem.First();
               }
      }
    }