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. KVC、KVO

    概述 由于ObjC主要基于Smalltalk进行设计,因此它有很多类似于Ruby.Python的动态特性,例如动态类型.动态加载.动态绑定等.今天我们着重介绍ObjC中的键值编码(KVC).键值监听( ...

  2. 11.hibernate的连接查询

    1.创建如下javaweb项目结构 2.在项目的src下创建hibernate.cfg.xml主配置文件 <?xml version="1.0" encoding=" ...

  3. 0. Java开发中的23种设计模式详解(转)

    设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...

  4. Java 字符串比较,String 中的一些方法 == 和 equals 的详解

    "==" 是比较的是两个对象的内存地址,而equals方法默认情况下是比较两个对象的内存地址. 1.String str = "hello"  生成的字符串,首 ...

  5. StretchBlt 提高图片显示质量的方法

    通过SetStretchMode(STRETCH_HALFTONE)实现,同时注意重新设置画刷起点 LRESULT CMainDlg::OnPaint(UINT uMsg, WPARAM wParam ...

  6. 去除VisualStudio中拼写错误检测的红色波浪线

    去除VisualStudio中拼写错误检测的红色波浪线 在Visual Assistant中将 Underline spelling errors in comments and strings us ...

  7. grub引导centos

    下面来主要讲一下在grub下来引导centos: 其步骤如下; a   进入grub的命令模式. b  先熟悉一下grub  的一些命令 grub>help c  熟悉一下cat命令 d  ro ...

  8. spring配置文件详解【总结】

    知其然,知其所以然 <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns=&qu ...

  9. WCF证书创建方法

    A.创建证书: (1)将创建证书工具makecert.exe放到任意地方.可以把该文档中的makecert.exe工具复制粘贴到任意目录. (2)doc命令去到makecert.exe的路径,然后输入 ...

  10. Git Bash 简单操作

    在Windows下使用Git Bash,用的是Linux命令,常用几个文件操作命令如下: Windows命令 Linux命令 意义 cd e:\xxx cd /e/xxx 切换到xxx目录 cd pw ...