Programmatical binding

9 posts, 0 answers
  1. MaiK
    MaiK avatar
    23 posts
    Member since:
    Mar 2018

    Posted 01 Oct 2018 Link to this post

    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!!!

     

     

  2. Dimitar
    Admin
    Dimitar avatar
    2841 posts

    Posted 01 Oct 2018 Link to this post

    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.
  3. MaiK
    MaiK avatar
    23 posts
    Member since:
    Mar 2018

    Posted 04 Oct 2018 Link to this post

    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! :)

     

  4. Dimitar
    Admin
    Dimitar avatar
    2841 posts

    Posted 04 Oct 2018 Link to this post

    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.
  5. MaiK
    MaiK avatar
    23 posts
    Member since:
    Mar 2018

    Posted 04 Oct 2018 in reply to Dimitar Link to this post

    Hi again,

     

    That worked perfectly :)

     

    Thank you very much Dimitar, Best regards!

  6. MaiK
    MaiK avatar
    23 posts
    Member since:
    Mar 2018

    Posted 09 Oct 2018 Link to this post

    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!

  7. Hristo
    Admin
    Hristo avatar
    1512 posts

    Posted 10 Oct 2018 Link to this post

    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.
  8. MaiK
    MaiK avatar
    23 posts
    Member since:
    Mar 2018

    Posted 11 Oct 2018 Link to this post

    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!

  9. Hristo
    Admin
    Hristo avatar
    1512 posts

    Posted 11 Oct 2018 Link to this post

    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.
Back to Top