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

Custom single grid cell with 2 labels (read only)

3 Answers 40 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 07 Nov 2016, 11:02 PM

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)

 

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 08 Nov 2016, 09:40 AM
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.
0
Simon
Top achievements
Rank 1
answered on 08 Nov 2016, 10:08 AM

Hi,

Your solution works.

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

 

Thanks anyway.

 

 

0
Dimitar
Telerik team
answered on 08 Nov 2016, 10:38 AM
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.
Tags
GridView
Asked by
Simon
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Simon
Top achievements
Rank 1
Share this question
or