求助:关于DevExpress的GridControl数据源的问题

denisabc 2016-12-14 11:08:41
有个问题请教各位大神,如果数据源中有字段为数组,应该怎么设置才能显示到gridview中。比如:
class A
{
private string itemA;
private string[] itemB;
public ItemA{ get;set;}
public ItemB{get;set;}
}

List<A> lst = new List<A>;
for(var i=0;i<100;i++)
{
A a = new A();
a.ItemA = "AAAA";
a.ItemB = {"1","2","3","4"};
lst.Add(a);
}

GridControl1.DataSource = lst;

GirdView中的Colunms应该如何设置,才能显示数据???
...全文
392 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
denisabc 2016-12-18
  • 打赏
  • 举报
回复
研究了几天,还是没有直接方法,数组字段不能像普通字段那样绑定后用FieldName直接显示出来。只能变通一下,GridView里用非绑定列,通过类索引器取出数组元素来显示了。 结贴
浴浴兮 2016-12-14
  • 打赏
  • 举报
回复
引用 14 楼 denisabc 的回复:
我不是要显示成一个字符串,而是要将一个字符串数组按元素显示在不同的Column内
233 Dev的控件不太自由 _(:3」∠)_ 如果B数组的最大长度固定的话 就可以增加相同数量的属性 不过感觉这样写很不优雅 但是如果要动态写就天啦噜了... _(:3」∠)_ 如果对UI没有要求 那还不如放在那一列的Detail表里呢
denisabc 2016-12-14
  • 打赏
  • 举报
回复
我不是要显示成一个字符串,而是要将一个字符串数组按元素显示在不同的Column内
浴浴兮 2016-12-14
  • 打赏
  • 举报
回复
因为我是用换行符拼接的数组 可能你行长度设置了只能显示一行 或者拉的太扁了 或者你把\r\n换成逗号或者空格 就能在一行显示了
denisabc 2016-12-14
  • 打赏
  • 举报
回复
引用 11 楼 a6733351018 的回复:
public string ItemA { get; set; } public string[] ItemB { get; set; } public string ItemC { get { if (ItemB != null) { return string.Join("\r\n", ItemB); } else { return null; } } } GridControl1 设置FileName为ItemB的列不可见 设置FileName为ItemC的列的Caption为ItemB
谢谢回复! 不过,按照你的思路ItemC = "1\r\n2\r\n3\r\n4" 只能显示为 “1”
浴浴兮 2016-12-14
  • 打赏
  • 举报
回复
public string ItemA { get; set; } public string[] ItemB { get; set; } public string ItemC { get { if (ItemB != null) { return string.Join("\r\n", ItemB); } else { return null; } } } GridControl1 设置FileName为ItemB的列不可见 设置FileName为ItemC的列的Caption为ItemB
denisabc 2016-12-14
  • 打赏
  • 举报
回复
转成字符串来显示是没问题的,我就想请教下,如果是数据源的记录中有数组字段的话,有什么办法能够显示出来
exception92 2016-12-14
  • 打赏
  • 举报
回复
引用 7 楼 denisabc 的回复:
就是这样,而不是显示ItemB对应的“1”“2”“3”“4”
转成char[] 数组 再处理一下 成字符串。
denisabc 2016-12-14
  • 打赏
  • 举报
回复
呵呵 不好意思 疏忽了 应该是 public string ItemA{ get;set;} publicstring[] ItemB{get;set;}
denisabc 2016-12-14
  • 打赏
  • 举报
回复

就是这样,而不是显示ItemB对应的“1”“2”“3”“4”
exception92 2016-12-14
  • 打赏
  • 举报
回复
引用 4 楼 denisabc 的回复:
[quote=引用 3 楼 duanzi_peng 的回复:] [quote=引用 2 楼 denisabc 的回复:] [quote=引用 1 楼 duanzi_peng 的回复:] 设置列的FileName字段。 https://search.devexpress.com/?q=richEditControl%20Syntax%20highlight&m=Documentation 官网 搜用法
FieldName = ???; “ItemB[0]” 这样肯定是不行的[/quote] ItemA 能显示么[/quote] ItemA 显示没问题,ItemB显示为“System.String”“System.String”“System.String”“System.String”,而不是我想要的“1”“2”“3”“4”[/quote] 转成char[] 数组 再处理一下 成字符串不就行了。 public ItemA{ get;set;} public ItemB{get;set;} 这2个声明不对吧,封装字段不对。
denisabc 2016-12-14
  • 打赏
  • 举报
回复
显示是这样 “System.String[]”“System.String[]”“System.String[]”“System.String[]”
denisabc 2016-12-14
  • 打赏
  • 举报
回复
引用 3 楼 duanzi_peng 的回复:
[quote=引用 2 楼 denisabc 的回复:] [quote=引用 1 楼 duanzi_peng 的回复:] 设置列的FileName字段。 https://search.devexpress.com/?q=richEditControl%20Syntax%20highlight&m=Documentation 官网 搜用法
FieldName = ???; “ItemB[0]” 这样肯定是不行的[/quote] ItemA 能显示么[/quote] ItemA 显示没问题,ItemB显示为“System.String”“System.String”“System.String”“System.String”,而不是我想要的“1”“2”“3”“4”
exception92 2016-12-14
  • 打赏
  • 举报
回复
引用 2 楼 denisabc 的回复:
[quote=引用 1 楼 duanzi_peng 的回复:] 设置列的FileName字段。 https://search.devexpress.com/?q=richEditControl%20Syntax%20highlight&m=Documentation 官网 搜用法
FieldName = ???; “ItemB[0]” 这样肯定是不行的[/quote] ItemA 能显示么
denisabc 2016-12-14
  • 打赏
  • 举报
回复
引用 1 楼 duanzi_peng 的回复:
设置列的FileName字段。 https://search.devexpress.com/?q=richEditControl%20Syntax%20highlight&m=Documentation 官网 搜用法
FieldName = ???; “ItemB[0]” 这样肯定是不行的
exception92 2016-12-14
  • 打赏
  • 举报
回复

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧