zoukankan      html  css  js  c++  java
  • WPF Combo box 获取选择的Tag

    string str1 = ((ComboBoxItem)this.cboBoxRate1553B.Items[this.cboBoxRate1553B.SelectedIndex]).Tag.ToString();
    
    string str2 = (this.cboBoxRate1553B.SelectedItem as ComboBoxItem).Tag.ToString();

    不知道为什么只能先转换为var 或者string类型,再转化为其他类型。

    I have a combo box like this

        <ComboBox Name="myMenu">
            <ComboBoxItem Content="Question 1" Tag="1"  />
            <ComboBoxItem Content="Question 2" Tag="2"  />
            <ComboBoxItem Content="Question 3" Tag="3"  />
            <ComboBoxItem Content="Question 4" Tag="4"  />
        </ComboBox>
    

    How can I programmatically set the selected index by Tag Value? E.g. 'myMenu.selectedTag = 3' and Question 3 would be the selected item?

    I want something easier than my current solution really...

          int tagToSelect = 3;
          foreach (ComboBoxItem item in myMenu.Items)
          {
              if(item.Tag.Equals(tagToSelect)
              {
                   myMenu.SelectedItem = item;
              }
          }
  • 相关阅读:
    UVA 10066 The Twin Towers
    UVA 10192 Vacation
    hdu 5018 Revenge of Fibonacci
    hdu 5108 Alexandra and Prime Numbers
    UVA 10252
    UVA 10405最长公共子序列
    数塔
    hdu 2602
    面向对象(五)
    面向对象(三)
  • 原文地址:https://www.cnblogs.com/jexwn/p/4569149.html
Copyright © 2011-2022 走看看