Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 208939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:52:15+00:00 2026-05-11T17:52:15+00:00

I have a set of ‘dynamic data’ that I need to bind to the

  • 0

I have a set of ‘dynamic data’ that I need to bind to the GridControl. Up until now, I have been using the standard DataTable class that’s part of the System.Data namespace. This has worked fine, but I’ve been told I cannot use this as it’s too heavy for serialization across the network between client & server.

So I thought I could easy replicate a ‘cut-down’ version of the DataTable class by simply having a type of List<Dictionary<string, object>> whereby the List represents the collection of rows, and each Dictionary represents one row with the column names and values as a KeyValuePair type. I could set up the Grid to have the column DataField properties to match those of the keys in the Dictionary (just like I was doing for the DataTable’s column names.

However after doing

gridControl.DataSource = table;
gridControl.RefreshDataSource();

The grid has no data…

I think I need to implement IEnumerator – any help on this would be much appreciated!

Example calling code looks like this:

var table = new List<Dictionary<string,object>>();

var row = new Dictionary<string, object>
{
    {"Field1", "Data1"},
    {"Field2", "Data2"},
    {"Field3", "Data3"}
};

table.Add(row);

gridControl1.DataSource = table;
gridControl1.RefreshDataSource();
  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:52:15+00:00Added an answer on May 11, 2026 at 5:52 pm

    Welcome to the wonderful world of System.ComponentModel. This dark corner of .NET is very powerful, but very complex.

    A word of caution; unless you have a lot of time for this – you may do well to simply serialize it in whatever mechanism you are happy with, but rehydrate it back into a DataTable at each end… what follows is not for the faint-hearted ;-p

    Firstly – data binding (for tables) works against lists (IList/IListSource) – so List<T> should be fine (edited: I misread something). But it isn’t going to understand that your dictionary is actually columns…

    To get a type to pretend to have columns you need to use custom PropertyDescriptor implementations. There are several ways to do this, depending on whether the column definitions are always the same (but determined at runtime, i.e. perhaps from config), or whether it changes per usage (like how each DataTable instance can have different columns).

    For “per instance” customisation, you need to look at ITypedList – this beast (implemented in addition to IList) has the fun task of presenting properties for tabular data… but it isn’t alone:

    For “per type” customisation, you can look at TypeDescriptionProvider – this can suggest dynamic properties for a class…

    …or you can implement ICustomTypeDescriptor – but this is only used (for lists) in very occasional circumstances (an object indexer (public object this[int index] {get;}“) and at least one row in the list at the point of binding). (this interface is much more useful when binding discrete objects – i.e. not lists).

    Implementing ITypedList, and providing a PropertyDescriptor model is hard work… hence it is only done very occasionally. I’m fairly familiar with it, but I wouldn’t do it just for laughs…


    Here’s a very, very simplified implementation (all columns are strings; no notifications (via descriptor), no validation (IDataErrorInfo), no conversions (TypeConverter), no additional list support (IBindingList/IBindingListView), no abstraction (IListSource), no other other metadata/attributes, etc):

    using System.ComponentModel;
    using System.Collections.Generic;
    using System;
    using System.Windows.Forms;
    
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            PropertyBagList list = new PropertyBagList();
            list.Columns.Add("Foo");
            list.Columns.Add("Bar");
            list.Add("abc", "def");
            list.Add("ghi", "jkl");
            list.Add("mno", "pqr");
    
            Application.Run(new Form {
                Controls = {
                    new DataGridView {
                        Dock = DockStyle.Fill,
                        DataSource = list
                    }
                }
            });
        }
    }
    class PropertyBagList : List<PropertyBag>, ITypedList
    {
        public PropertyBag Add(params string[] args)
        {
            if (args == null) throw new ArgumentNullException("args");
            if (args.Length != Columns.Count) throw new ArgumentException("args");
            PropertyBag bag = new PropertyBag();
            for (int i = 0; i < args.Length; i++)
            {
                bag[Columns[i]] = args[i];
            }
            Add(bag);
            return bag;
        }
        public PropertyBagList() { Columns = new List<string>(); }
        public List<string> Columns { get; private set; }
    
        PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            if(listAccessors == null || listAccessors.Length == 0)
            {
                PropertyDescriptor[] props = new PropertyDescriptor[Columns.Count];
                for(int i = 0 ; i < props.Length ; i++)
                {
                    props[i] = new PropertyBagPropertyDescriptor(Columns[i]);
                }
                return new PropertyDescriptorCollection(props, true);            
            }
            throw new NotImplementedException("Relations not implemented");
        }
    
        string ITypedList.GetListName(PropertyDescriptor[] listAccessors)
        {
            return "Foo";
        }
    }
    class PropertyBagPropertyDescriptor : PropertyDescriptor
    {
        public PropertyBagPropertyDescriptor(string name) : base(name, null) { }
        public override object GetValue(object component)
        {
            return ((PropertyBag)component)[Name];
        }
        public override void SetValue(object component, object value)
        {
            ((PropertyBag)component)[Name] = (string)value;
        }
        public override void ResetValue(object component)
        {
            ((PropertyBag)component)[Name] = null;
        }
        public override bool CanResetValue(object component)
        {
            return true;
        }
        public override bool ShouldSerializeValue(object component)
        {
            return ((PropertyBag)component)[Name] != null;
        }
        public override Type PropertyType
        {
            get { return typeof(string); }
        }
        public override bool IsReadOnly
        {
            get { return false; }
        }
        public override Type ComponentType
        {
            get { return typeof(PropertyBag); }
        }
    }
    class PropertyBag
    {
        private readonly Dictionary<string, string> values
            = new Dictionary<string, string>();
        public string this[string key]
        {
            get
            {
                string value;
                values.TryGetValue(key, out value);
                return value;
            }
            set
            {
                if (value == null) values.Remove(key);
                else values[key] = value;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set up a site that is correctly using basic CRUD functionality succesfully.
I have set of records which I need to search using criteria. But criteria
I have set up a version control system using TortoiseSVN at my home to
I have set up a UITableView with 3 sections that pulls from 3 NSArrays
I have set up a little snippet that will take an autoresponder code for
I have set up the spellchecker for the example installation configuration that comes with
I have set up an ISPconfig server and am now trying to install curl.
I have set of plugins which were created in Java 1.6 before, now I
I have set many lables and I want them to show the data from
I have set up a cron job, using the great whenever gem. every 1.minute

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.