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

Column Resize

3 Answers 28 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rafael
Top achievements
Rank 1
Rafael asked on 01 Jul 2014, 04:54 AM
Hi,


I have had a good look at the forums and I can't find a way of doing the following:
 - When a user resizes a column so that its value does no longer fit its width, I want it to hide the LEFT side of its value.
  I.E. If the value is "1234567890123467", once the value is too long to show, i want it to hide the characters on the LEFT; the value could become "...7890123467"

I thought RIGHTTOLEFT = True would do it, but it does not.

Thanks in advance!

Rafael  

3 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 03 Jul 2014, 02:07 PM
Hi Rafael,

Thank you for contacting us.

You can implement you own, custom logic which will measure the text and according to the size of the cell will show or not dots in front of the text. This can happen in the ViewCellFormatting event of RadGridView:
private Dictionary<int, string> originalTextCache = new Dictionary<int, string>();
void Grid_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement is GridHeaderCellElement && e.ColumnIndex == 1)
    {
        if (!this.originalTextCache.ContainsKey(e.ColumnIndex))
        {
            this.originalTextCache[e.ColumnIndex] = e.Column.HeaderText;
        }
 
        e.Column.HeaderText = this.originalTextCache[e.ColumnIndex];
        e.CellElement.AutoEllipsis = false;
        Size elementSize = e.CellElement.Size;
        Size textSize = TextRenderer.MeasureText(e.Column.HeaderText, e.CellElement.Font);
        if (elementSize.Width == 0)
        {
            elementSize = new Size(e.Column.Width, textSize.Height);
        }
 
        if (elementSize.Width > 0 && elementSize.Width <= textSize.Width)
        {
            StringBuilder text = new StringBuilder(e.Column.HeaderText);
            do
            {
                if (text.Length == 0)
                {
                    break;
                }
 
                text = text.Remove(0, 1);
            }
            while ((textSize = TextRenderer.MeasureText(text.ToString(), e.CellElement.Font)).Width > elementSize.Width);
 
            if (text.Length > 0)
            {
                text = text.Remove(0, 1);
            }
 
            string newCellText = string.Format("{0}{1}", "..", text.ToString());
            e.Column.HeaderText = newCellText;
        }
    }
}

I hope this information is useful.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Rafael
Top achievements
Rank 1
answered on 07 Jul 2014, 04:05 AM
Thanks, I will have a look at this, and get back to you on how I get on.
0
George
Telerik team
answered on 09 Jul 2014, 12:22 PM
Hello Rafael,

Let me know, should you have further questions.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Rafael
Top achievements
Rank 1
Answers by
George
Telerik team
Rafael
Top achievements
Rank 1
Share this question
or