0

I am new in the using of DevExpress. I need to design and bind a complex DataGrid.

I have designed it using the Designer. The datagrid is of type Master-Detail, and it contains the 'MainGrid' and other detail grids. One of them is of type: 'advBandedGridView'

The design of the MainGrid is as shown below:

enter image description here

And the design of the 'advBandedGridView' is as follows:

enter image description here

Now, I need to fill my DataGrid using Lists collections, so I used the following Code:

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;

        }
    }
}

However, I found that the result is built as a new DataGrid that has not any designed form. I mean that the detail tabs that I define in the Designer are not appeared in the resulted grid.

The result is as follows:

enter image description here

Notes

  1. The design of the resulted grid which is totally different from my design, I think it is just like the Lists objects.
  2. The other problem which is the appearance of : "WindowsFormsApplication2.Morphos" and "WindowsFormsApplication2.Semantics" at the cells of the grid rather than the values that I passed!
halfer
  • 19,824
  • 17
  • 99
  • 186
AyaZoghby
  • 341
  • 3
  • 7
  • 16

1 Answers1

1

Firstly, you should create associations between your data object properties and GridView columns via GridColumn.FildName property.
For your main view (gridView2) it looks like this:

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

Please read the following article for more details: Creating Columns and Binding Them to Data Fields

Secondly, you can not directly bind columns to object's nested properties (for example to MyExpansions.semantics.subclasses.SemID).

To bypass this restriction you can use several approaches:

  1. The simplest approach is using Unbound Columns and the corresponding ColumnView.CustomUnboundColumnData event (you can handle this event to provide data from nested objects).
  2. You can also use the approach demonstrated in the following KB article: How to display and edit complex data properties in grid columns

Thirdly, to get official and guaranteed answer you should address any urgent question related to any DevExpress products directly to DevExpress Support Center.

DmitryG
  • 17,677
  • 1
  • 30
  • 53