This is a migrated thread and some comments may be shown as answers.

using a name instead of a index in ColumnGroups

5 Answers 48 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 16 Feb 2016, 11:31 PM

 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

5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 17 Feb 2016, 06:53 AM
Hi Joe,

Thank you for writing.

The GridViewColumnGroup constructor has an overload, where it accepts specifying the group Name as :
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
0
Accepted
Mahmoud
Top achievements
Rank 1
answered on 17 Feb 2016, 08:28 AM

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());

0
Joe
Top achievements
Rank 2
answered on 17 Feb 2016, 12:41 PM

Thanks Mahmoud -- 

That should do it, I appreciate it!

 

--Joe

0
Joe
Top achievements
Rank 2
answered on 17 Feb 2016, 12:46 PM

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

0
Stefan
Telerik team
answered on 17 Feb 2016, 01:02 PM
Hello,

The constructor is available in the 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
Tags
GridView
Asked by
Joe
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Mahmoud
Top achievements
Rank 1
Joe
Top achievements
Rank 2
Share this question
or