WPF dataGrid下的ComboBox的绑定
2014-10-20 15:40
417 查看
WPF dataGrid下的ComboBox的绑定
Wpf中dataGrid中的某列是comboBox解决这个问题费了不少时间,不废话了直接上代码
xaml 代码
xmal的代码写完了。下面写后台代码。
.cs代码如下:
为什么用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解决这个问题费了不少时间,不废话了直接上代码
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 DataGridComboBox绑定enum
- WPF中DataGrid的ComboBox的简单绑定方式(绝对简单)
- WPF中DataGrid的ComboBox的简单绑定方式(绝对简单)
- WPF使用DataGridComboBoxColumn完成绑定
- [WPF]DataGridTemplateColumn使用ComboBox绑定Dictionary细节记录
- WPF使用DataGridComboBoxColumn完成绑定
- WPF使用DataGridComboBoxColumn完成绑定
- wpf datagrid中的 DataGridComboBoxColumn数据绑定
- MVVM WPF 使用 datagrid 绑定 comboBox
- WPF使用DataGridComboBoxColumn完成绑定
- WPF--MVVM之DataGrid ComboBox数据源绑定枚举
- WPF使用DataGridComboBoxColumn完成绑定
- WPF 控件DataGrid绑定
- ComboBox在WPF中的绑定示例:绑定项、集合、转换,及其源代码
- WPF DataGridComboBoxColumn的使用方法
- DataGrid中的子控件Combox之数据源绑定(WPF)
- WPF:后台获取DataGrid列的绑定字段。
- easyui datagrid动态修改editor时动态绑定combobox的数据
- WPF DataGrid、ListView 简单绑定
- WPF_DataGrid_ItemsSource绑定