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

Programmatical binding

8 Answers 11 Views
GridView
This is a migrated thread and some comments may be shown as answers.
MaiK
Top achievements
Rank 1
MaiK asked on 01 Oct 2018, 06:41 AM

Hello,

 

I want to binding some properties to gridview programmatically. I have object hierarchy like that:

public class CLASS_A
{
      String propA;
      int propB;
      CLASS_B propC;
}
 
public class CLASS_B
{
      String propA;
      int propB;
      bool propC;
}

 

The datasource will be a list of CLASS_A, and i want to bind propA from CLASS_A and some properties of CLASS_B.

There is no problem to binding properties from CLASS_A with field name, but I try same doing something like "propC.propA" but doesnt work.

What I am doing wrong?

 

Thank you and Regards!!!

 

 

8 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 01 Oct 2018, 09:54 AM
Hello Maik,

This should work but you need to have public properties in your classes. An example is available here: Binding to Sub Objects | RadGridView.

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
MaiK
Top achievements
Rank 1
answered on 04 Oct 2018, 08:09 AM

Hello Dimitar,

Thanks for your reply. Properties are public, but I write wrong my example :/

CLASS_A propC is "Object" type declared. But the specific type is "CLASS_B".How can I solve this?

 

Thank you and regards! :)

 

0
Dimitar
Telerik team
answered on 04 Oct 2018, 10:03 AM
Hello Mikel,

In this case, you will need to manually set the text of the cell. Here is an example valid for the code from the article:
private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.Column.Name == "Car" && e.Row.DataBoundItem != null)
    {
        var data = e.Row.DataBoundItem as Person;
        e.CellElement.Text = ((Car)data.Car).Model;
    }
}

I have attached a complete project as well.

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
MaiK
Top achievements
Rank 1
answered on 04 Oct 2018, 10:43 AM

Hi again,

 

That worked perfectly :)

 

Thank you very much Dimitar, Best regards!

0
MaiK
Top achievements
Rank 1
answered on 09 Oct 2018, 01:51 PM

Hello,

 

I got other issue related with this post. Bindings works OK, but now filtering and grouping doesnt work.

I have been searching o the documentation and I dont see nothing about it. What i  must change for search and grouping work correctly?

 

thank you!

0
Hristo
Telerik team
answered on 10 Oct 2018, 10:53 AM
Hi,

Please make sure that the EnableFiltering and EnableGrouping properties of the RadGridView in your project are set to true. I am also able to filter the grid in the project my colleague sent previously. However, please note that if you group by the Car property and its type is object it will create a single group and also the available fields will be for type object. If you are still having the Car property defined with type object in order to group and filter by it, you can consider using CustomFiltering and CustomGrouping: 
Additionally, you may also consider creating a custom type converter which will be responsible for formatting the text in the cells and creating a new Car object whenever you edit the Car column. You can follow the example demonstrated here: https://docs.telerik.com/devtools/winforms/gridview/columns/converting-data-types.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
MaiK
Top achievements
Rank 1
answered on 11 Oct 2018, 09:43 AM

Hello,

 

I am using type object and groups and filters doesnt work in that columns.

I am trying with customGrouping event, but GroupKey comes empty :/

 

Thank you!

0
Hristo
Telerik team
answered on 11 Oct 2018, 03:35 PM
Hi Mikel, 

The group key will come empty because with custom grouping it is your responsibility to set it and define how many groups you will have. This is also demonstrated in the code snippet of the CustomGrouping event handler: https://docs.telerik.com/devtools/winforms/gridview/grouping/custom-grouping. Generally speaking, setting the type of the property in this scenario to object is not support. If possible please consider defining it with its actual type.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
MaiK
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
MaiK
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or