C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace WpfApplication2
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<Person> list = new List<Person>()
{
new Person{Id=,Name="张三",Sex="男"},
new Person{Id=,Name="李四",Sex="男"},
new Person{Id=,Name="王五",Sex="女"},
new Person{Id=,Name="赵六",Sex="男"},
new Person{Id=,Name="孙七",Sex="女"}
};
cb.ItemsSource=list;
cb.SelectedIndex = ;
} private void Button_Click(object sender, RoutedEventArgs e)
{
if (cb.SelectedItem != null)
{
Person p = cb.SelectedItem as Person;
MessageBox.Show("Id:"+p.Id.ToString()+",姓名:"+p.Name+",性别:"+p.Sex);
}
}
}
public class Person
{
private int id; public int Id
{
get { return id; }
set { id = value; }
}
private string name; public string Name
{
get { return name; }
set { name = value; }
} private string sex; public string Sex
{
get { return sex; }
set { sex = value; }
} }
}

XAML

<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<ComboBox x:Name="cb" DisplayMemberPath="Name"/>
<Button Content="Show" Click="Button_Click" />
</StackPanel>
</Grid>
</Window>

运行效果:

点击“Show”按钮,弹框显示下拉框选中项的详细信息:

C#后台绑定ComboBox的更多相关文章

  1. winform快速开发平台 -> 快速绑定ComboBox数据控件

    通常我们在处理编辑窗体时.往往会遇到数据绑定.例如combobox控件绑定数据字典可能是我们经常用到的.然而在我的winform快速开发平台中我是如何处理这个频繁的操作呢? 首先,我们要绑定combo ...

  2. datatable绑定comboBox显示数据[C#]

    实现功能: datatable绑定comboBox,在下拉菜单中显示对应数据 实现方法: 1.生成datatable,并为combox绑定数据源: comboBox1.DataSource = dt1 ...

  3. winform c#绑定combobox下拉框 年度代码。

    winform c#绑定combobox下拉框 年度代码. comboBox1.Items.AddRange("});//邦定数据 comboBox1.Text = DateTime.Now ...

  4. Linq to SQL 绑定 ComboBox

    最近学习Linq to SQL,发现Linq是一个开发轻量数据库的好东西,大大简化了数据连接.查询过程.但是在绑定ComBoBox的时间发现了一个问题:Linq查询后得到的数据tolist后,只能实现 ...

  5. datatable绑定comboBox,在下拉菜单中显示对应数据

    实现功能: datatable绑定comboBox,在下拉菜单中显示对应数据 实现方法: .生成datatable,并为combox绑定数据源: comboBox1.DataSource = dt1; ...

  6. GridView后台绑定数据列表方法

    在很多时候数据绑定都是知道了数据表中的表字段来绑定GridView控件的,那时候我就有个想法希望通过表明来查询数据库中的字段来动态的绑定GirdView控件数据并提供了相关的操作列,在网上找了一些资料 ...

  7. WPF DATAGrid 空白列 后台绑定列 处理

    原文:WPF DATAGrid 空白列 后台绑定列 处理 AutoGenerateColumns <DataGrid x:Name="dataGrid" Margin=&qu ...

  8. HighChat动态绑定数据 数据后台绑定(四)

    后台绑定数据,直接返回json数据 IList<SummaryHour> adHourData = summarybll.FindList(str); List<, , , , , ...

  9. HighChat动态绑定数据 数据后台绑定(三)

    今天看了几位大佬的博客,学到了一些,现在分享一下,也作为以后的参考 不多说看代码 1.后台代码 public ActionResult Ajax2() { ReportData reportData ...

随机推荐

  1. js--事件对象的理解2

    实例1:一串跟着鼠标飞舞的div <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...

  2. 《JS权威指南学习总结--6.4检测属性》

    内容要点: js对象可以看做属性的集合,我们经常会检测集合中成员的所属关系-----判断某个属性是否存在于某个对象中,可以通过in运算符,hasOwnPreperty()和propertyIsEnum ...

  3. 转-CSS优先级(权重)解析

    1.多个选择器可能会选择同一个元素,有3个规则,从上到下重要性降低: !important的用户样式 !important的作者样式 作者样式 用户样式 浏览器定义的样式 2. CSS规范为不同类型的 ...

  4. MPI编程简介[转]

    原文地址http://blog.csdn.net/qinggebuyao/article/details/8059300 3.1 MPI简介 多线程是一种便捷的模型,其中每个线程都可以访问其它线程的存 ...

  5. Java 反射 调用私有域和方法(setAccessible)

    Java 反射 调用私有域和方法(setAccessible) @author ixenos AccessibleObject类 Method.Field和Constructor类共同继承了Acces ...

  6. 浙大pat 1011题解

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  7. 使用 mulan-1.5.0 如何构造.arff文件

    1. 为什么要使用mulan 我用mulan来做多标签数据的分类,但是mulan的输入数据由两个文件控制,一个是data.arff文件,这个文件列出的所有的属性以及这些属性值的类型和他们对应的值.la ...

  8. Vultr优惠码20美元享受20GB SSD和2T流量

    美国vps主机商vultr最新优惠码:20FOR30,只限新注册用户,点击注册链接,进入后台Billing,找到Gift code,输入20FOR30,点击apply,就能免费获得20美元的账户余额. ...

  9. 高性能MySQL第2,3章性能相关 回顾笔记

    1.  基准测试(benchmark)   不管是新手还是专家都要熟悉基准测试,benchmark测试是对系统的一种压力测试,目标是为了掌握在特定压力下系统的行为.也有其他原因:如重现系统状态,或者是 ...

  10. mac xmind快捷键

    tab:新建分支 command +z : 撤销 command + "+":放大 command + "-":缩小 shift + enter : 文字换行