WPF dataGrid下的ComboBox的绑定

Wpf中dataGrid中的某列是comboBox解决这个问题费了不少时间,不废话了直接上代码

xaml 代码

<DataGridTemplateColumn Header="组名">

  <DataGridTemplateColumn.CellTempLate>

           <DataTemplate>
    <ComboBox SelectedValue="{Binding Path=Name}" ItemSource={Binding Path=SelectionList,RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor}}></ComboBox> <DataTemplate> <DataGridTemplateColumn.CellTempLate> </DataGridTemplateColumn >

xmal的代码写完了。下面写后台代码。

.cs代码如下:

public ObservableCollection<string> SelectionList //ObservableCollection这是一个类,需引用(using System.Collections.ObjectModel)

{

  get{return _selectionList;}

  set{_selectionList=value;}

}

private observableCollection<string> _selectionList=new observableCollection<string>(); //这个是实现的重要一步

为什么用ObservableCollection类,可自行网上搜索

接下来应该给SelectionList 添加下来值了。

SelectionList .Add("Name1");

SelectionList .Add("Name2");

这样ComboBox的下来框就有Name1和Name2了,当然SelectionList也可以添加后台查询出来的DataTabel的值,无非就是加个循环而已

这是值给ComboBox添加值而已,最后一步,把从数据库查出来的值绑定到ComboBox上,让其实默认展示项

(select name ,field ...from table )查询出一个DataTable的集合

dataGrid的name(自己起的名字)dataGrid.ItemSource=DataTable.DefaultView;

这样查询出的name将会绑定在ComboBox上。

WPF dataGrid下的ComboBox的绑定的更多相关文章

  1. WPF Datagrid 动态生成列 并绑定数据

    原文:WPF Datagrid 动态生成列 并绑定数据 说的是这里 因为列头是动态加载的 (后台for循环 一会能看到代码) 数据来源于左侧列 左侧列数据源 当然num1 属于临时的dome使用  可 ...

  2. WPF DataGrid某列使用多绑定后该列排序失效,列上加入 SortMemberPath 设置即可.

    WPF DataGrid某列使用多绑定后该列排序失效 2011-07-14 10:59hdongq | 浏览 1031 次  悬赏:20 在wpf的datagrid中某一列使用了多绑定,但是该列排序失 ...

  3. WPF DataGrid 每行ComboBox 内容不同的设置方法

    <toolkit:DataGridComboBoxColumn x:Name="DgCbcSignal" Header="信号源" SelectedIte ...

  4. wpf DATAgrid模板中button 命令绑定以及命令参数绑定

    场景:视频上传功能,上传列表使用DataGrid控件,视频有不同的状态对应不同的操作,DataGrid中最后一列为操作列,里面是Button控件.希望点击Button后执行对应的操作,但是设置Butt ...

  5. WPF DataGrid 绑定数据及时更新的处理

    原文:WPF DataGrid 绑定数据及时更新的处理 默认情况下datagrid 绑定数据源后,在界面编辑某一列后,数据不会及时更新到内存对象中.如在同一行上有一个命令对来获取 当前选中行(内存对象 ...

  6. WPF DataGrid绑定一个组合列

    WPF DataGrid绑定一个组合列 前台: <Page.Resources>        <local:InfoConverter x:Key="converter& ...

  7. WPF DataGrid 绑定行双击行命令

    WPF DataGrid 绑定行双击行命令 <DataGrid ...> <DataGrid.InputBindings> <MouseBinding MouseActi ...

  8. WPF DataGrid 双击行 获得绑定数据

    原文:WPF DataGrid 双击行 获得绑定数据 1)增加事件 2)增加对象获取 1)事件代码 Datagrid 增加事件 MouseDoubleClick="dataGrid_Mous ...

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

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

随机推荐

  1. ABAP操作EXCEL (号称超级版)

    [转自http://www.cnblogs.com/VerySky/articles/2170014.html] *------------------------------------------ ...

  2. JavaScript测试代码

    <!-- 在谷歌浏览器上的console运行 --> //变量 var netPrice = 8.99; alert(netPrice); //字符串方法 var string1 = &q ...

  3. python实例3-天气小模块

    调用中国天气的一小段代码,抓取 #! /usr/bin/python # coding = utf-8 # ToDo: get weather info from weather.com.cn # A ...

  4. rails 字符串 转化为 html

    simple_format http://apidock.com/rails/v4.0.2/ActionView/Helpers/TextHelper/simple_format http://api ...

  5. android客户端登录&注册的实现

    MainActivity多线程的实现: package com.example.loginconnect; import java.lang.ref.WeakReference; import jav ...

  6. php 通用redis类

    php 通用redis类 <?php /** * redis操作类 * 说明,任何为false的串,存在redis中都是空串. * 只有在key不存在时,才会返回false. * 这点可用于防止 ...

  7. DL二(稀疏自编码器 Sparse Autoencoder)

    稀疏自编码器 Sparse Autoencoder 一神经网络(Neural Networks) 1.1 基本术语 神经网络(neural networks) 激活函数(activation func ...

  8. java 获取pdf内容

    1. 说明 将pdf中的文字读取处理还有一些限制:1. 文档的安全属性不能过于严格 2. 不能存在图片. 2. 直接贴相关的源码 有两种读取方式,maven对应的pom文件 <dependenc ...

  9. bzoj 2005: [Noi2010]能量采集 筛法||欧拉||莫比乌斯

    2005: [Noi2010]能量采集 Time Limit: 10 Sec  Memory Limit: 552 MB[Submit][Status][Discuss] Description 栋栋 ...

  10. 英语发音规则---Y字母

    英语发音规则---Y字母 一.总结 一句话总结: 1.Y字母在单词最前面读发[j]? yes /jes/ [jɛs] n. 是 yard /jɑːd/ [jɑd] n. 院子 yellow /'jel ...