WPF在Devexpress的gridcontrol中ComboBox绑定数据
程序员文章站
2022-06-07 18:34:54
...
Use the CellTemplate property to define a template that specifies the visualization of column cells. The binding source for the CellTemplate template is represented by the EditGridCellData class.
The EditGridCellData class has the Value property that provides access to the cell editable value. Use the RowData.Row property to access a row's data object property: {Binding RowData.Row.[YourPropertyName]}
The code sample belows shows how to use a custom ComboBoxEdit within grid cells:
其中{Binding RowData.Row.[YourPropertyName]} 绑定可以更换为其他的:
<ObjectDataProvider x:Key="SpectrometerState" MethodName="GetValues" ObjectType="{x:Type core:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type Type="Infrastructure:SpectrometerState"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
//然后再需要的地方添加绑定 ,x:Name=“Part_Editor”是必须的
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:ComboBoxEdit x:Name="PART_Editor" ItemsSource="{Binding Source={StaticResource SpectrometerState}}"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
以下是官网提供的代码
public ObservableCollection<CountryCities> Items {
get {
if(this._Items == null) {
this._Items = new ObservableCollection<CountryCities>();
CountryCities usa = new CountryCities() {
Country = "USA",
Cities = new List<string> { "Washington, D.C.", "New York", "Los Angeles", "Las Vegas" },
City = "Los Angeles"
};
this._Items.Add(usa);
CountryCities germany = new CountryCities() {
Country = "Germany",
Cities = new List<string> { "Berlin", "Munich", "Frankfurt" },
City = "Munich"
};
this._Items.Add(germany);
CountryCities russia = new CountryCities() {
Country = "Russia",
Cities = new List<string> { "Moscow", "Saint-Petersburg" },
City = "Moscow"
};
this._Items.Add(russia);
}
return this._Items;
}
}
<dxg:GridControl AutoGenerateColumns="AddNew" EnableSmartColumnsGeneration="True" ItemsSource="{Binding Items}">
<dxg:GridColumn FieldName="Country"/>
<dxg:GridColumn FieldName="City">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:ComboBoxEdit x:Name="PART_Editor" ItemsSource="{Binding RowData.Row.Cities}"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
<dxg:GridControl.View>
<dxg:TableView/>
</dxg:GridControl.View>
</dxg:GridControl>
上一篇: 自定义数据类型
下一篇: 正则怎么同时匹配两种模式
推荐阅读
-
DevExpress的GridControl的使用以及怎样添加列和绑定数据源
-
WPF中DataGrid在没有数据的时候也可以显示水平滚动条
-
Flex中在Tree绑定数据后自动展开树节点的方法
-
WPF中关于ListBox绑定数据的问题
-
WPF DevExpress的GridControl数据,表格数据导出到excel
-
WPF 中DevExpress14.2 GridControl控件的使用
-
WPF学习笔记 ComboBox的数据绑定
-
WPF在Devexpress的gridcontrol中ComboBox绑定数据
-
WPF C#将DataGrid绑定到数据库中读取的数据,并把变化更新到数据库
-
怎样将一个数据库里的所有数据表的名字绑定到ComboBox中