Unbound columns

2 posts, 0 answers
  1. Kim
    Kim avatar
    47 posts
    Member since:
    Jul 2013

    Posted 29 Aug 2013 Link to this post

    Here is my scenario, 

    I bind my grid with a List of foo. 

    foo contains a list of bar, which are custom, user defined fields. Each foo has the identical list of bars, but the "Value" of each bar is different, depending on what the user put in.

    In my scenario, foo has a list with 2 bars

    bar 1 Fieldname="CustomField1"
    bar 1 Value="My Field"

    bar 2 Fieldname="CustomField2"
    bar 2 Value="My Field 2"

    My grid will have 5 columns, ID, Name, Desc, CustomField1, CustomField2.

    When I bind, ID, Name, Desc populate with data, but of course, CustomField1 and CustomField2 are empty, which I expect.

    What is the best way to get the data into these columns?

    I hope this isn't too confusing!


    Sample Code;

    namespace sample
        class foo
            public int ID { get; set; }
            public string Name { get; set; }
            public string Desc { get; set; }
            private List<bar> _customFields;
            public foo ()
                _customFields = new List<bar>();
        class bar
            public string FieldName { get; set; }
            public string Value { get; set; }

  2. Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    4086 posts

    Posted 02 Sep 2013 Link to this post

    Hello Kim,

    Thank you for contacting Telerik Support.

    The appropriate solution in this particular case is loading programatically Hierarchical data in grid. I have modified a little your code in order to obtain the result displayed in the attached picture:
    public partial class Form1 : Form
        public Form1()
            List<foo> listFoo = new List<foo>()
                new foo(1,"foo 1","desc foo 1"),
                new foo(2,"foo 2","desc foo 2"),
                new foo(3,"foo 3","desc foo 3"),
            this.radGridView1.MasterTemplate.DataSource = listFoo;
            this.radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.F
            List<bar> listBar = new List<bar>()
                new bar(1,"bar 1.0", "bar value 1.0"),
                new bar(1,"bar 1.1", "bar value 1.1"),
                new bar(2,"bar 2.0", "bar value 2.0"),
                new bar(1,"bar 1.2", "bar value 1.2"),
                new bar(2,"bar 2.1", "bar value 2.1"),
                new bar(1,"bar 1.3", "bar value 1.3"),
                new bar(3,"bar 3.0", "bar value 3.0"),
            GridViewTemplate template = new GridViewTemplate();
            template.DataSource = listBar;
            template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
            relation.ChildTemplate = template;
            relation.RelationName = "FooBar";
    class foo
        public int ID { get; set; }
        public string Name { get; set; }
        public string Desc { get; set; }
        //private List<bar> _customFields;
        //public foo ()
        //    _customFields = new List<bar>();
        public foo(int iD, string name, string desc)
            this.ID = iD;
            this.Name = name;
            this.Desc = desc;
    class bar
        public int ParentID { get; set; }
        public string FieldName { get; set; }
        public string Value { get; set; }
        public bar(int parentID, string fieldName, string value)
            this.ParentID = parentID;
            this.FieldName = fieldName;
            this.Value = value;

    I hope this information helps. Should you have further questions, I would be glad to help.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top