0

我是使用 DevExpress 的新手。我需要设计和绑定一个复杂的 DataGrid。

我使用 Designer 设计了它。数据网格的类型为 Master-Detail,它包含“MainGrid”和其他详细信息网格。其中之一是类型:'advBandedGridView'

MainGrid的设计如下图所示:

在此处输入图像描述

而“advBandedGridView”的设计如下:

在此处输入图像描述

现在,我需要使用 Lists 集合填充我的 DataGrid,所以我使用了以下代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            ArrayList a = new ArrayList();
            Term_Space_Grid t = new Term_Space_Grid("x", "y", true, "z");
            t.expansions = new List<MyExpansions>();
            t.expansions.Add(new MyExpansions(0, "Aya", 0, 0, 0, 0, 0));
            a.Add(t);
            resultsGridControl.DataSource = a;


        }
    }

    public class Term_Space_Grid
    {
        public string x { get; set; }
        public string y { get; set; }
        public string g { get; set; }
        public bool z { get; set; }
        public List<MyExpansions> expansions { get; set; }

        public Term_Space_Grid(string x, string y, bool z, string g)
        {
            this.x = x;
            this.y = y;
            this.z = z;
            this.g = g;

        }
    }
    public class MyExpansions
    {
        public Morphos morphos { get; set; }
        public Semantics semantics { get; set; }  

        public MyExpansions(int morphoID, string morphoDerivation, int synID, int subID, int supID, int hasID, int insID)
        {
            this.morphos = new Morphos(morphoID, morphoDerivation);
            this.semantics = new Semantics(synID, subID, supID, hasID, insID);

        }

    }

    public class Morphos
    {
         //public List<Morph> morph{ get; set; }
        public Morph morph { get; set; }

         public Morphos(int morphoID, string morphoDerivation)
        {

            //this.morph = new List<Morph>();
            //this.morph.Add(new Morph(morphoID, morphoDerivation));
            this.morph = new Morph(morphoID, morphoDerivation);
         }
    }      

    public class Semantics
    {
        public List<Sem> synonyms { get; set; }
        public List<Sem> subClasses { get; set; }
        public List<Sem> superClasses { get; set; }
        public List<Sem> hasInstances { get; set; }
        public List<Sem> instanceOf { get; set; }

        public Semantics(int id1,int id2, int id3, int id4, int id5 )
        {
            this.synonyms = new List<Sem>();
            this.subClasses = new List<Sem>();
            this.superClasses = new List<Sem>();
            this.hasInstances = new List<Sem>();
            this.instanceOf = new List<Sem>();

            this.synonyms.Add(new Sem(id1));
            this.subClasses.Add(new Sem(id2));
            this.superClasses.Add(new Sem(id3));
            this.hasInstances.Add(new Sem(id4));
            this.instanceOf.Add(new Sem(id5));
        }
    }

     public class Morph
    {
         public int MorphoID { get; set; }
        public string MorphoDerivation { get; set; }

         public Morph(int morphoID, string morphoDerivation)
        {
            this.MorphoID = morphoID;
            this.MorphoDerivation = morphoDerivation;
         }
    }
    public class Sem
    {
        public int SemID { get; set; }
        //public string MorphoDerivation { get; set; }

        public Sem(int semID)
        {
            this.SemID = semID;

        }
    }
}

但是,我发现结果是作为没有任何设计形式的新 DataGrid 构建的。我的意思是我在设计器中定义的详细信息选项卡不会出现在结果网格中。

结果如下:

在此处输入图像描述

笔记

  1. 结果网格的设计与我的设计完全不同,我认为它就像 Lists 对象一样。
  2. 另一个问题是网格单元格中出现“WindowsFormsApplication2.Morphos”和“WindowsFormsApplication2.Semantics”,而不是我传递的值!
4

1 回答 1

1

首先,您应该通过GridColumn.FildName属性在数据对象属性和 GridView 列之间创建关联。
对于您的主视图 ( gridView2),它看起来像这样:

// gridColumn1
this.gridColumn1.Caption = "ID";
this.gridColumn1.FieldName = "x"; // associate this column with Term_Space_Grid.x property
this.gridColumn1.Name = "gridColumn1";

请阅读以下文章了解更多详细信息:创建列并将它们绑定到数据字段

其次,您不能直接将列绑定到对象的嵌套属性(例如绑定到MyExpansions.semantics.subclasses.SemID)。

要绕过此限制,您可以使用多种方法:

  1. 最简单的方法是使用Unbound Columns和相应的ColumnView.CustomUnboundColumnData事件(您可以处理此事件以提供来自嵌套对象的数据)。
  2. 您还可以使用以下知识库文章中演示的方法:如何在网格列中显示和编辑复杂数据属性

第三,要获得官方和有保证的答案,您应该直接向DevExpress 支持中心解决与任何 DevExpress 产品相关的任何紧急问题。

于 2013-01-28T15:22:39.400 回答