WPF Devexpress GridControl Value与Display转换
直入主题吧!开发中往往需要将代码转换成中文显示在表格中。
如下图

下面就直接贴代码了.
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.Shapes;
using System.Data; namespace WpfApplication1
{
/// <summary>
/// Window4.xaml 的交互逻辑
/// </summary>
public partial class Window4 : Window
{ public static List<Areas> Data
{
get { return Areas.getgg(); }
} public Window4()
{
InitializeComponent();
gridcontrol.ItemsSource = NwindData.DataPerson;
} } public class NwindData
{ public static DataTable DataPerson
{
get { return setPerson(); }
} private static DataTable setPerson()
{
DataTable dt = new DataTable();
dt.Columns.Add("id",Type.GetType("System.Int32"));
dt.Columns.Add("username", Type.GetType("System.String"));
dt.Columns.Add("areaid", Type.GetType("System.Int32")); //这里的类型一定要和Area中的Areaid类型一致不然就显示不中文
DataRow row = dt.Rows.Add(); row[] = "";
row[] = "张三";
row[] = ""; row = dt.Rows.Add();
row[] = "";
row[] = "李四";
row[] = "";return dt;
} } public class Areas
{
int areaid; public int Areaid
{
get { return areaid; }
set { areaid = value; }
}
string areaName; public string AreaName
{
get { return areaName; }
set { areaName = value; }
}
public Areas(int areaid, string areaname)
{
this.areaid = areaid;
this.areaName = areaname;
} public static List<Areas> getgg()
{
List<Areas> list = new List<Areas>();
list.Add(new Areas(,"中国"));
list.Add(new Areas(,"美国"));
return list; }
}
}
XAML代码
<Window xmlns:my="clr-namespace:WpfApplication1" x:Class="WpfApplication1.Window4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<dxg:GridControl Name="gridcontrol" >
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="id" MinWidth="100" Header="ID"/>
<dxg:GridColumn FieldName="username" MinWidth="100" Header="姓名"/>
<dxg:GridColumn FieldName="areaid" MinWidth="100" Header="地区ID"/>
<dxg:GridColumn FieldName="areaid"
EditSettings="{dxe:ComboBoxSettings DisplayMember=AreaName, ValueMember=Areaid, ItemsSource={x:Static my:Window4.Data}}" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView ShowGroupPanel="False" Name="ds" />
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
</Grid>
</Window>
到这里就ok了!
WPF Devexpress GridControl Value与Display转换的更多相关文章
- [Irving] Wpf DevexPress GridControl 获取选中行
WPF前台绑定事件代码: <RelayAction TargetControl="{Binding ElementName=GCInstoragePart}" MethodN ...
- DevExpress GridControl使用(转)
DevExpress GridControl使用 (一)原汁原味的表格展示 Dev控件中的表格控件GridControl控件非常强大.不过,一些细枝末节的地方有时候用起来不好找挺讨厌的.使用过程中,多 ...
- DevExpress GridControl使用方法
一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 (1).gridView.AddN ...
- 实现DevExpress GridControl 只有鼠标双击后才进行修改数据
1. 实现DevExpress GridControl 只有鼠标双击后才进行修改数据:修改GridView.OptionsBehavior.EditorShowMode属性为Click 2. 实现De ...
- DevExpress GridControl 使用方法技巧 总结 收录整理
一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 ().gridView.AddNe ...
- Devexpress GridControl z
http://minmin86121.blog.163.com/blog/static/4968115720144194923578/ 1 AllowNullInput=False; --Devexp ...
- DevExpress GridControl 单元格添加进度条(ProgressBar)
首先可以使用DevExpress GridControl 自带的进度条控件. 但是我要用一个方法来设置所以的单元格进度,而不是每个单元格都要设置一遍,同时我想要根据进度值不同,进度条显示不同的颜色. ...
- DevExpress GridControl+UserControl实现分页
志向不过是记忆的奴隶,生气勃勃地降生,但却很难成长. —— 莎士比亚 时隔一年,我写随笔真的很随意,想起了就来博客园写写,想不起来就任由懒惰支配着我.不过我到觉得这不是什么坏事,你不用为了完成某事而让 ...
- WPF Color、String、Brush转换
原文:WPF Color.String.Brush转换 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/BYH371256/article/detai ...
随机推荐
- 【BZOJ3064】CPU监控(线段树)
[BZOJ3064]CPU监控(线段树) 题面 BZOJ 洛谷 题解 神仙\(zsy\)出在了\(noip\)模拟的题目.(然而\(zsy\)出的还是这题的升级版) 首先明确一点,这题是一个吉司机线段 ...
- POJ 3348 Cows | 凸包——童年的回忆(误)
想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...
- Luogu 3369 我用线段树骗了一道平衡树题……
这篇博客毫无意义-- 只是表达一下我仍然会写树状数组和线段树-- 题目链接 #include <cstdio> #include <cstring> #include < ...
- 【bzoj1937】 Shoi2004—Mst 最小生成树
http://www.lydsy.com/JudgeOnline/problem.php?id=1937 (题目链接) 题意 一个无向图,给出一个生成树,可以修改每条边的权值,问最小修改多少权值使得给 ...
- Zabbix利用msmtp+mutt发送邮件报警
操作系统:CentOS 7 Web环境:Nginx+MySQL+PHP zabbix版本:zabbix-2.4.8.tar.gz 邮件服务:msmtp-1.4.32.tar.bz2 #http ...
- 梯度下降法求解函数极大值-Matlab
目录 目录题目作答1. 建立函数文件ceshi.m2. 这是调用的命令,也可以写在.m文件里3. 输出结果题外话 题目 作答 本文使用MATLAB作答 1. 建立函数文件ceshi.m functio ...
- 关于RESTful的理解
如何更好的理解RESTful? (转自https://sanwen8.cn/p/54czrEO.html) 在测试开发中,我们经常接触到API,在调用API时候特别是第三方API时候,我们常常陷入以下 ...
- SpringBoot(十三):springboot 小技巧
原文出处: 纯洁的微笑 一些springboot小技巧.小知识点. 初始化数据 我们在做测试的时候经常需要初始化导入一些数据,如何来处理呢?会有两种选择,一种是使用Jpa,另外一种是Spring JD ...
- css实现0.5像素的边框
公司的设计师在做设计图的时候都是以iphone6(宽为750物理像素)为基准进行设计的.iphone6的设备像素比(即css像素与物理像素的比例)是2,所以设计师在设计图画了边框为1px的box的时候 ...
- The Ph.D. Grind
The Ph.D. Grind A Ph.D. Student Memoir Summary The Ph.D. Grind, a 122-page e-book, is the first know ...