Nested Object Alias

DGV Framework can access nested objects in the collection. This can be achieved using the ~ Notation when setting the column alias.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DGV.Framework;

namespace csDemo
{
    public partial class Form1 : Form
    {
        public class User
        {
            public string Name { get; set; }
            public int Age { get; set; }
            public string Gender { get; set; }

            public Contacts Contacts { get; set; }
        }
        
        public class  Contacts
        {
            public string Email { get; set; }
            public string Phone { get; set; }


        }

        public Form1() => InitializeComponent();
       

        private void Form1_Load(object sender, EventArgs e)
        {
            //create sample the records
            List<User> usersList = new List<User>();
            for (int i = 0; i < 10; i++)
            {
                usersList.Add(new User
                {
                    Age = 28,
                    Name = "Kim Too FLex",
                    Gender = "Male",
                    Contacts = new Contacts()
                    {
                        Email = "[email protected]",
                        Phone = "+1 800 000 000" 
                    }
                });
            }
            
           // access nested object
            _dataGridView.SetColumnAlias("Phone", "Contacts~Phone");
            _dataGridView.SetColumnAlias("Email", "Contacts~Email");

            //Bind the list to datagrid view
            _dataGridView.Bind(usersList);
        }
    }
}

Nested Objects

     _dataGridView
     .SetColumnAlias("Email", "Account~User~Name");

Last updated

Was this helpful?