zoukankan      html  css  js  c++  java
  • WPF 控件使用之ComboBox

    下面是ComboBox的简单实用

    XAML:

       <Grid>
            <ComboBox Height="23" Margin="12,12,0,0" Name="comboBox1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120" />
            <Button Height="23" Margin="21,53,69,0" Name="button1" VerticalAlignment="Top" Click="button1_Click">Get ComboBox select value</Button>
        </Grid>
    

    C# Code:

        public partial class ComboBoxTest : Window
        {
            public ComboBoxTest()
            {
                InitializeComponent();
                Bind();
            }
    
            public void Bind()
            {
                IList<customer> customList = new List<customer>();
                customList.Add(new customer() { ID = 3, Name = "Tom" });
                customList.Add(new customer() { ID = 4, Name = "Bob" });
                customList.Add(new customer() { ID = 5, Name = "Cat" });
                comboBox1.ItemsSource = customList;
                comboBox1.DisplayMemberPath = "Name";
                comboBox1.SelectedValuePath = "ID";
                comboBox1.SelectedValue = 4;
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                MessageBox.Show(comboBox1.SelectedValue.ToString());
            }
        }
    
        public class customer
        {
            public int ID{ get; set;}
            public string Name { get; set; }
        }
    

      

  • 相关阅读:
    20165312 我期望的师生关系
    zookeeper04---ZAB协议
    zookeeper03-集群搭建
    zookeeper02
    Zookeeper01
    防止重复提交
    手动抛出异常事务回滚问题
    redis-07主从复制
    redis06-事务
    Redis-05持久化
  • 原文地址:https://www.cnblogs.com/linlf03/p/2174462.html
Copyright © 2011-2022 走看看