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

WrapText and AutoSizeRows = true

7 Answers 561 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 24 Jun 2009, 12:13 PM
Hello,

Q1 2009 Winform controls.

I am having a little trouble with wrapping text and autosizing rows.   I have a gridview on a form with a checkbox at the top to define whether to show the full cell text or not.

As far as wrapping text and the rows autosizing, I cannot even get this to work correctly. The problems are:

1..Wrapping of text and resizing of rows only seems to work correctly if the line this.radGridViewExceptions.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; is not commented out.  If this is commented out and I set the column widths in the swtich, the description column, which has the most text, only shows 2 lines of text fully. The 3rd and final line in that cell shows about 10% of the top of the 3rd line, the rest is cut off.

2..The cursor changes to an arrow pointing up and down, like it is going to let me resize the row, but I cannot resize it even though AllowResize is set to true in the designer properties

3...My functional requirement is that on clicking the checkbox to not show full text, the rows go back to only show one line of text and do not wrap.  So in the event handler for the checkbox I go through the columns in the grid and set WrapText to the checked state of the checkbox.  This either enables or disables wrapping ok, but the row height when going from wraptext =true to wraptext = false does not change so I am left with thick and thin rows.  I want all rows to be thin, ie all the same height.

Thanks in advance,

My code is below:

     private void SetupForm() 
        { 
            try 
            { 
                // Add the events 
                this.radGridViewExceptions.ViewCellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(radGridViewExceptions_ViewCellFormatting); 
                this.radGridViewExceptions.DataSource = m_objExceptions.GetLast30DaysExceptions(); 
               
                // Wrapping text only seems to work correctly if this is not commented out
                // and I do not set the column widths below
                // this.radGridViewExceptions.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; 
               
                this.radGridViewExceptions.MasterGridViewTemplate.AllowColumnReorder = false
                this.radGridViewExceptions.MasterGridViewTemplate.AllowColumnResize = false
                this.radGridViewExceptions.AutoSizeRows = true
 
                // Format the columns 
                foreach (GridViewColumn column in radGridViewExceptions.Columns) 
                { 
                    switch (column.HeaderText) 
                    { 
                        case "When_Occured": 
                        case "Description": 
                            column.Width = 200
                            break; 
 
                        case "App_Assembly": 
                            column.Width = 120
                            break; 
 
                        case "App_Assembly_Version": 
                            column.Width = 150
                            break; 
 
                        default: 
                            column.Width = 100
                            break; 
                    } 
 
                    column.WrapText = true; //radCheckBoxShowFullText.Checked; 
                } 
                m_bFormLoaded = true
            } 
            catch (Exception ex) 
            { 
                ShowException(ex); 
                m_bFormLoaded = false
            } 
        } 
 

 


7 Answers, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
answered on 26 Jun 2009, 11:59 AM
Hello,

Does anyone have any ideas on this?  If the functionality is not possible I have to abondon RadGridView and use standard .Net controls only.

Thanks,
Paul
0
Victor
Telerik team
answered on 26 Jun 2009, 12:50 PM
Hello Paul,

Here is a code snippet which, based on the state of a checkbox, sets the AutoSizeRows property, the WrapText property and the row height. When the checkbox is checked, WrapText is true, AutoSizeRows is true and you see the whole text. When  the checkbox is unchecked all rows have equal 50 pixel height.
public Form1()  
{  
    InitializeComponent();  
    this.radGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;  
    this.radCheckBox1.Checked = true;  
}  
 
private void radCheckBox1_ToggleStateChanged(object sender, StateChangedEventArgs args)  
{  
    this.radGridView1.AutoSizeRows = this.radCheckBox1.Checked;  
    foreach (GridViewDataColumn c in this.radGridView1.Columns)  
    {  
        c.WrapText = this.radCheckBox1.Checked;  
    }  
 
    if (!this.radCheckBox1.Checked)  
    {  
        foreach (GridViewRowInfo r in this.radGridView1.Rows)  
        {  
            r.Height = 50;  
        }  
    }  

Generally, if you require quicker answers I would suggest you to use our support ticketing system which has a higher priority than the forum threads.

Write back if you need futher assistance.

Regards,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Paul
Top achievements
Rank 1
answered on 26 Jun 2009, 01:16 PM
Same problem.  Some rows do not show the full text.  See screen shots attached.

There are 2 screen shots, one shows columns set to fill the grid and other screen shot shows grid columns set to my preferred widths.  As you can see each screen shot shows a different row with text cut off


Screen shot showing full text is not showing in some cells

Screen shot showing full text is not showing in some cells
0
Paul
Top achievements
Rank 1
answered on 26 Jun 2009, 01:57 PM
I think I have found the problem.

I wanted the cells to have padding so I am formatting them via

private void radGridViewExceptions_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) 
    e.CellElement.Padding = m_padding; 

The m_padding is private member set at the top of the class to save creating new padding vars for each cell.  It is set with values (5,0,5,0)

Is there another way to set cell padding so wraptext actually works correctly?

Thanks,
Paul
0
Victor
Telerik team
answered on 01 Jul 2009, 05:26 PM
Hello Paul,

I tried to reproduce the wrong behavior with the Northwind database (Employees table), but it was working  fine. Please list the steps which are required to reproduce the behavior. It will be best if you can send me a sample application so that I can examine it.

I am looking forward to your reply.

Greetings,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Paul
Top achievements
Rank 1
answered on 02 Jul 2009, 07:59 AM
<admin>link removed - please use support ticketing system to post projects</admin>

Column 3 shows that you cannot see the word "now"


0
Accepted
Victor
Telerik team
answered on 03 Jul 2009, 06:52 PM
Hi Paul,

It turns out that there was an issue with RadGridView in the previous release. This is issue has been fixed in current Q2 2009 version, which you can download from your account.
 

Greetings,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Paul
Top achievements
Rank 1
Answers by
Paul
Top achievements
Rank 1
Victor
Telerik team
Share this question
or