Custom single grid cell with 2 labels (read only)

4 posts, 0 answers
  1. Simon
    Simon avatar
    7 posts
    Member since:
    Apr 2014

    Posted 07 Nov Link to this post

    Hi,

     

    I have been trying to override CellFormatting to reformat a string value to look like 2 labels, one above the other (in the same cell) e.g.:

    Freddy Smith (standard font)

      On the phone (smaller font)

     

    To do this I have been trying to create 2 RadHostControls, each one hosting a Label control and using .Location. .MaxSize etc properties to try to position the 2 labels (or their host controls) within the cell.

    But somehow the first RadHostControl seems to take over all the spacein the cell (If I put the background to red I can see it occupies the whole cell).

    Do you have any example where you have used multiple labels?

    Many thanks.

     

    (Using Q1 2016)

     

  2. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 08 Nov Link to this post

    Hi Simon,

    Thank you for writing.

    It is not a good approach to use the formatting events to add controls to a cell element. In this case, you can use the HTML-like formatting to show the labels:
    private void RadGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (e.Row is GridViewDataRowInfo)
        {
            e.CellElement.DisableHTMLRendering = false;
            e.CellElement.Text = @"<html> label1 <br /> label 2";
        
    }

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

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Simon
    Simon avatar
    7 posts
    Member since:
    Apr 2014

    Posted 08 Nov in reply to Dimitar Link to this post

    Hi,

    Your solution works.

    I assume it faster to render than creating a user control with 2 labels?

     

    Thanks anyway.

     

     

  5. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 08 Nov Link to this post

    Hi Simon,

    Yes, this is faster because only one element is rendered. For more complex scenarios you should consider creating a custom cell.

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

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top