C#后台绑定ComboBox
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的更多相关文章
- winform快速开发平台 -> 快速绑定ComboBox数据控件
通常我们在处理编辑窗体时.往往会遇到数据绑定.例如combobox控件绑定数据字典可能是我们经常用到的.然而在我的winform快速开发平台中我是如何处理这个频繁的操作呢? 首先,我们要绑定combo ...
- datatable绑定comboBox显示数据[C#]
实现功能: datatable绑定comboBox,在下拉菜单中显示对应数据 实现方法: 1.生成datatable,并为combox绑定数据源: comboBox1.DataSource = dt1 ...
- winform c#绑定combobox下拉框 年度代码。
winform c#绑定combobox下拉框 年度代码. comboBox1.Items.AddRange("});//邦定数据 comboBox1.Text = DateTime.Now ...
- Linq to SQL 绑定 ComboBox
最近学习Linq to SQL,发现Linq是一个开发轻量数据库的好东西,大大简化了数据连接.查询过程.但是在绑定ComBoBox的时间发现了一个问题:Linq查询后得到的数据tolist后,只能实现 ...
- datatable绑定comboBox,在下拉菜单中显示对应数据
实现功能: datatable绑定comboBox,在下拉菜单中显示对应数据 实现方法: .生成datatable,并为combox绑定数据源: comboBox1.DataSource = dt1; ...
- GridView后台绑定数据列表方法
在很多时候数据绑定都是知道了数据表中的表字段来绑定GridView控件的,那时候我就有个想法希望通过表明来查询数据库中的字段来动态的绑定GirdView控件数据并提供了相关的操作列,在网上找了一些资料 ...
- WPF DATAGrid 空白列 后台绑定列 处理
原文:WPF DATAGrid 空白列 后台绑定列 处理 AutoGenerateColumns <DataGrid x:Name="dataGrid" Margin=&qu ...
- HighChat动态绑定数据 数据后台绑定(四)
后台绑定数据,直接返回json数据 IList<SummaryHour> adHourData = summarybll.FindList(str); List<, , , , , ...
- HighChat动态绑定数据 数据后台绑定(三)
今天看了几位大佬的博客,学到了一些,现在分享一下,也作为以后的参考 不多说看代码 1.后台代码 public ActionResult Ajax2() { ReportData reportData ...
随机推荐
- 3DTouch--2
苹果太贱了! 3D Touch 只能在真机上面试,模拟器没办法玩! ------------- 描述有点粗燥.....有6S 在手上玩得童鞋会更加清楚,只有玩过才更加体验到. 首先 有几个要知道的手势 ...
- MATLAB制作符合IEEE标准的图插入Latex
1.MATLAB最好保存为eps格式,虽然IEEE也支持png等其他格式,但是MATLAB在保存为png格式时,很容易在后期插图时,出现分辨率不足等问题. 2. MATLAB在save as图片的时候 ...
- 自定义MVC框架(二) -基于XML文件
1.oracle的脚本 create table STUDENT ( sid NUMBER primary key, sname ), age NUMBER, pwd ) ) create seque ...
- git clone 出现 RPC failed 错误的解决方案
今天使用git clone一个大型项目的时候出现了如下错误:
- MaskEdit组件的EditText属性和Text属性
MaskEdit组件主要是EditMask属性 是string属性. 掩码字符串EditMask属性分为3个部分,分别用分号隔开,形式是“XXXXX;X;X” 第一部分是掩码字符串的主要部分,它确定输 ...
- php观察者模式
观察者模式(有时又被称为发布/订阅模式)是软件设计模式的一种.在此种模式中,一个目标对象管理所有相依于它的观察者对象,并且在它本身的状态改变时主动发出通知.这通常透过呼叫各观察者所提供的方法来实现.此 ...
- ZIP文件解压
public class DZip { /// <summary> /// 压缩为ZIP文件 /// </summary> public void Zip(string dir ...
- js数据转换
javascript有如下数据类型的转换方法:一,转换成数字 xxx*1.0 转换成字符串 xxx+"" 二,从一个值中提取另一种类型的值,并完成转换工作. 1.提取字符串中的整数 ...
- ural 1356. Something Easier(数论,哥德巴赫猜想)
1356. Something Easier Time limit: 1.0 secondMemory limit: 64 MB “How do physicists define prime num ...
- 游戏客户端嵌入页面出白边bug
需要使用 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > 这样的头部给页面才能去除与客 ...