直入主题吧!开发中往往需要将代码转换成中文显示在表格中。

如下图

下面就直接贴代码了.

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转换的更多相关文章

  1. [Irving] Wpf DevexPress GridControl 获取选中行

    WPF前台绑定事件代码: <RelayAction TargetControl="{Binding ElementName=GCInstoragePart}" MethodN ...

  2. DevExpress GridControl使用(转)

    DevExpress GridControl使用 (一)原汁原味的表格展示 Dev控件中的表格控件GridControl控件非常强大.不过,一些细枝末节的地方有时候用起来不好找挺讨厌的.使用过程中,多 ...

  3. DevExpress GridControl使用方法

    一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 (1).gridView.AddN ...

  4. 实现DevExpress GridControl 只有鼠标双击后才进行修改数据

    1. 实现DevExpress GridControl 只有鼠标双击后才进行修改数据:修改GridView.OptionsBehavior.EditorShowMode属性为Click 2. 实现De ...

  5. DevExpress GridControl 使用方法技巧 总结 收录整理

    一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 ().gridView.AddNe ...

  6. Devexpress GridControl z

    http://minmin86121.blog.163.com/blog/static/4968115720144194923578/ 1 AllowNullInput=False; --Devexp ...

  7. DevExpress GridControl 单元格添加进度条(ProgressBar)

    首先可以使用DevExpress GridControl 自带的进度条控件. 但是我要用一个方法来设置所以的单元格进度,而不是每个单元格都要设置一遍,同时我想要根据进度值不同,进度条显示不同的颜色. ...

  8. DevExpress GridControl+UserControl实现分页

    志向不过是记忆的奴隶,生气勃勃地降生,但却很难成长. —— 莎士比亚 时隔一年,我写随笔真的很随意,想起了就来博客园写写,想不起来就任由懒惰支配着我.不过我到觉得这不是什么坏事,你不用为了完成某事而让 ...

  9. WPF Color、String、Brush转换

    原文:WPF Color.String.Brush转换 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/BYH371256/article/detai ...

随机推荐

  1. RocketMQ生产者消息篇

    系列文章 RocketMQ入门篇 RocketMQ生产者流程篇 RocketMQ生产者消息篇 前言 上文RocketMQ生产者流程篇中详细介绍了生产者发送消息的流程,本文将重点介绍发送消息的通信模式以 ...

  2. 【Cf #290 B】Fox And Jumping(dp,扩展gcd)

    根据裴蜀定理,当且仅当选出来的集合的L[i]的gcd等于1时,才能表示任何数. 考虑普通的dp,dp[i][j]表示前i个数gcd为j的最少花费,j比较大,但状态数不多,拿个map转移就好了. $ \ ...

  3. JsonTools

    public class JsonTools { /// <summary> /// Generate Json string from the object /// </summa ...

  4. 解题:SCOI 2011 糖果

    题面 能把差分约束卡死的题,因为正解并不是差分约束,然而被我用一种奇怪的姿势过去了... 差分约束就是相等互相连零边,不超过/不低于从不多的一方向另一方连零边,超过/低于从少的一方向另一方连最小的边权 ...

  5. Python实现类似JavaScript 的Json对象

    Python实现类似JavaScript 的Json对象 用过js的都知道 js中json也是一个对象,所以可以直接通过class.attr 取值,当attr不存在时也不会报错,那么Python可不可 ...

  6. 关于javaweb中图片的存储问题

    图片上传到服务器,然后把上传路径保存到数据库,然后从数据库读出保存的路径显示到网站页面. 我们一般可以在CMS系统中将图片添加到图片服务器中(这个可以使用ftp来部署),然后图片上传到服务器后,在数据 ...

  7. 【题解】Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths Codeforces 741D DSU on Tree

    Prelude 很好的模板题. 传送到Codeforces:(* ̄3 ̄)╭ Solution 首先要会DSU on Tree,不会的看这里:(❤ ω ❤). 众所周知DSU on Tree是可以用来处 ...

  8. P4394 [BOI2008]Elect 选举

    P4394 [BOI2008]Elect 选举 题目描述 N个政党要组成一个联合内阁,每个党都有自己的席位数. 现在希望你找出一种方案,你选中的党的席位数要大于总数的一半,并且联合内阁的席位数越多越好 ...

  9. UIApplication概述

    1.通过类方法sharedApplication可以获得唯一实例 2.可以打开mail或者email,通过openUrl方法. 3.指定UIApplicationDelegate可以跟踪各种应用状态. ...

  10. JavaScript setInterval 与 setTimeout 区别

    setInterval:一直循环调用函数,不会停止:需要用 clearInterval 去停止 setTimeout:只调用一次