C# – DevExpress XtraGrid – 主/细节 – 显示格式

脚本

  • 我有一个DevExpress XtraGrid。
  • 显示的数据采用主/明细格式,单击行开头的“+”可展开该主行的详细信息。
  • 我已经通过将grids数据源绑定到包含它们自己的Dictionary属性的对象字典(以保存细节)来实现这一点。

问题

  • 我想要做的是格式化细节的特定列中的数据。
  • 但是,我无法掌握该列,大概是因为它是主行的子元素(因此不会被检查?)
  • 下面是我到目前为止尝试过的两个代码示例,它们不起作用。

尝试过的代码解决方案

gridView1.Columns["Price"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; gridView1.Columns["Price"].DisplayFormat.FormatString = "n4"; private void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e) { GridView View = sender as GridView; if (e.Column.FieldName == "Price") { e.Column.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; e.Column.DisplayFormat.FormatString = "n4"; } } 

非常感谢。

要格式化GridView中的值,您应首先获取此对象的实例。 几乎这样做的标准方法是处理Master GridView的MasterRowExpanded事件处理程序。 在此事件处理程序中,您还可以设置列的DisplayFormat:

 private void gridView1_MasterRowExpanded_1(object sender, CustomMasterRowEventArgs e) { GridView master = sender as GridView; GridView detail = master.GetDetailView(e.RowHandle, e.RelationIndex) as GridView; detail.Columns["SomeColumn"].DisplayFormat = .... }