using a name instead of a index in ColumnGroups

6 posts, 1 answers
  1. Joe
    Joe avatar
    26 posts
    Member since:
    Feb 2012

    Posted 16 Feb Link to this post

     The following code works:

     view.ColumnGroups.Add(new GridViewColumnGroup("AutoPOD"));
                view.ColumnGroups.Add(new GridViewColumnGroup("Addresses"));
                view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
                view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
                view.ColumnGroups[1].Rows.Add(new GridViewColumnGroupRow());
                view.ColumnGroups[1].Rows.Add(new GridViewColumnGroupRow());
               

     Is there a way to replace it with something like this, short of using variables:

     view.ColumnGroups.Add(new GridViewColumnGroup("AutoPOD"));
                view.ColumnGroups.Add(new GridViewColumnGroup("Addresses"));
                view.ColumnGroups["autoPOD"].Rows.Add(new GridViewColumnGroupRow());
                view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
                view.ColumnGroups["Addresses"].Rows.Add(new GridViewColumnGroupRow());
                view.ColumnGroups[1].Rows.Add(new GridViewColumnGroupRow());

    We have a lot of groups and having the name right there would help code readability a lot.

     

    Thanks,

     

    Joe

  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 17 Feb Link to this post

    Hi Joe,

    Thank you for writing.

    The GridViewColumnGroup constructor has an overload, where it accepts specifying the group Name as second paramether:
    view.ColumnGroups.Add(new GridViewColumnGroup("groupText", "groupName"));

    once the Name is specified, then you can use the indexer and access the group by name:
    view.ColumnGroups["groupName"]

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Mahmoud
    Mahmoud avatar
    10 posts
    Member since:
    Mar 2015

    Posted 17 Feb in reply to Joe Link to this post

    Hi Joe ,

    Use this code

     

    Telerik.WinControls.UI.ColumnGroupsViewDefinition view = new Telerik.WinControls.UI.ColumnGroupsViewDefinition();

    view.ColumnGroups.Add(new Telerik.WinControls.UI.GridViewColumnGroup("AutoPOD", "AutoPOD"));
    view.ColumnGroups.Add(new Telerik.WinControls.UI.GridViewColumnGroup("Addresses", "Addresses"));
    view.ColumnGroups["AutoPOD"].Rows.Add(new Telerik.WinControls.UI.GridViewColumnGroupRow());
    view.ColumnGroups["AutoPOD"].Rows.Add(new Telerik.WinControls.UI.GridViewColumnGroupRow());
    view.ColumnGroups["Addresses"].Rows.Add(new Telerik.WinControls.UI.GridViewColumnGroupRow());
    view.ColumnGroups["Addresses"].Rows.Add(new Telerik.WinControls.UI.GridViewColumnGroupRow());

  5. Joe
    Joe avatar
    26 posts
    Member since:
    Feb 2012

    Posted 17 Feb in reply to Mahmoud Link to this post

    Thanks Mahmoud -- 

    That should do it, I appreciate it!

     

    --Joe

  6. Joe
    Joe avatar
    26 posts
    Member since:
    Feb 2012

    Posted 17 Feb in reply to Stefan Link to this post

    Thank you Stefan --

     Did I miss this in the online documentation?  

    I did search / read it before posting.

    I should have used intelisense in VS better (I stopped after looking at the view.ColumnGroups.Add -- after you add the (new GridViewColumnGroup it shows the available overloads), it would have saved me some time.

     Thank you,

    Joe

  7. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 17 Feb Link to this post

    Hello,

    The constructor is available in the api reference of the documentation as well: http://docs.telerik.com/devtools/winforms/api/html/M_Telerik_WinControls_UI_GridViewColumnGroup__ctor_2.htm

    I am glad this works for you.

    Regards,
    Stefan
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready