Showing data in the class containing the class in the grid.

3 Answers 217 Views
GridView
özer
Top achievements
Rank 2
Veteran
Iron
özer asked on 21 May 2022, 09:19 AM

Hi. 

I have a class that has other classes as property in it.
I want to create a list from this class and display the list in the grid (as in the attached excel example).
Which tool should I use?

The "Incentive" class I want to use.

namespace Models.Domain
{
    public class Incentive
    {
        public string Tckn { get; set; } = string.Empty;
        public Ysys Ysys { get; set; } = new Ysys();
        public Abyob Aybob { get; set; } = new Abyob();
        public Oybyu Oybyu { get; set; } = new Oybyu();
        public Yybyu Yybyu { get; set; } = new Yybyu();
        public Yuoa Yuoa { get; set; } = new Yuoa();
        public Uidd Uidd { get; set; } = new Uidd();
    }
    public class Kanunlar 
    {
        public string ts { get; set; } = string.Empty;
        public string ios { get; set; } = "0";
    }
    public class Ysys : Kanunlar { } // 2828
    public class Abyob : Kanunlar { } //6111
    public class Oybyu : Kanunlar { } // 17103
    public class Yybyu : Kanunlar { } // 27103
    public class Yuoa : Kanunlar { } // 7316
    public class Uidd : Kanunlar { } // 3294
}

I want to create a view like this in GridView:

Can I do this with GridView or is there another tool I can use? Thank you in advance for your help.

 

3 Answers, 1 is accepted

Sort by
1
tar
Top achievements
Rank 2
Iron
Iron
Iron
answered on 23 May 2022, 11:40 PM | edited on 23 May 2022, 11:54 PM

There are 5 possible solutions:

1. Create a separate class with a flat structure where you map your data into and which you can use to display it in a grid, e.g.

    public class IncentiveDisplay
    {
        public string Tckn { get; set; } = string.Empty;
        public string Ysys_ts { get; set; } = string.Empty;
        public string Ysys_ios { get; set; } = "0";
        public string Abyob_ts { get; set; } = string.Empty;
        public string Abyob_ios { get; set; } = "0";
        ...
    }

2. Like 1. but with additional UniqueID and ParentID properties which you can use in a grid with self-referencing hierarchy.

3. Create separate classes for each the parent items and (each differently structured) child items which you can use in a grid with object relational hierarchy mode.

4. Use 2 to x grids where you display the child/nested elements of each selected parent item separately.

5. Simply do it right:

    public class Incentive {
        public string Tckn { get; set; }
        public string Name { get; set; }
        public string Ts   { get; set; }
        public string Ios  { get; set; }
    }
And just use 1 grid with filters, if needed ;)
1
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 May 2022, 10:56 AM
 Hello,   


@M. S., the provided detailed information is greatly appreciated. I have also updated your Telerik points for community effort.

@özer, RadGridView supports out-of-the-box binding to sub objects by intuitive and simple dot (.) syntax (specified through the FieldName property of declaratively bound columns): https://docs.telerik.com/devtools/winforms/controls/gridview/populating-with-data/binding-to-sub-objects 

Аlternatively, you can have a look at the following help article which demonstrates a sample approach how to show nested properties in RadPropertyGrid: https://docs.telerik.com/devtools/winforms/knowledge-base/show-nested-collections-in-propertygrid
Once the current record in the flat grid is selected, you can assign the respective object to the RadPropertyGrid.SelectedObject property. 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
özer
Top achievements
Rank 2
Veteran
Iron
answered on 04 Jun 2022, 11:18 AM

Thank you both for your answers. Also I apologize for being late for feedback.

For now I used this solution

5. Simply do it right:

    public class Incentive {
        public string Tckn { get; set; }
        public string Name { get; set; }
        public string Ts   { get; set; }
        public string Ios  { get; set; }
    }

And just use 1 grid with filters, if needed ;)

But I still think if I could use the Column Groups View method mentioned in https://docs.telerik.com/devtools/winforms/controls/gridview/view-definitions/column-groups-view

Dess | Tech Support Engineer, Principal
Telerik team
commented on 06 Jun 2022, 04:58 AM

Hi, özer,

I am glad that the provided possible solutions were helpful for your scenario. Feel free to use this approach that fits your requirements best. As to the ColumnGroupsViewDefinition, once you have any columns in RadGridView (either added automatically when assigning DataSource or added programmatically), you can define groups and organize the columns in these groups. Every column group can have an unlimited number of subgroups or rows containing columns. You can refer to the following section of the referred help article which demonstrates how to setup the view definition programmatically.

Tags
GridView
Asked by
özer
Top achievements
Rank 2
Veteran
Iron
Answers by
tar
Top achievements
Rank 2
Iron
Iron
Iron
Dess | Tech Support Engineer, Principal
Telerik team
özer
Top achievements
Rank 2
Veteran
Iron
Share this question
or