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

Column.BestFit() throws Object Reference Not Set error

1 Answer 56 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 04 Oct 2012, 07:26 PM
I've created a simple RadGridView with 2 columns and turned off displaying grid lines and I get the following error:

Object reference not set to an instance of an object.
   at Telerik.WinControls.UI.GridRowElement.UpdateSelectedState()

 
Seems that setting display.HideSelection=true causes BestFit to raise the error.

Here's the code that reproduces the problem:

private void GenerateConfigurationSummary(RadGridView display)
{
    const string colValue = "value";
    const string colHeader = "header";
    
    display.HideSelection = true;
    display.Rows.Clear();
    display.Columns.Clear();
    display.Columns.Add(colHeader);
    display.Columns.Add(colValue);
    display.ReadOnly = true;
    display.ShowColumnHeaders = false;
    display.ShowRowHeaderColumn = false;
    display.TableElement.DrawBorder = false;
 
    display.CellFormatting += (s, e) =>
    {
        if (e.Column.Name == colHeader)
            e.CellElement.Font = new System.Drawing.Font(e.CellElement.Font, System.Drawing.FontStyle.Bold); 
 
        e.CellElement.DrawBorder = false
    };
 
    try
    {
        display.Rows.Add("Test Row 1", "Test Value 1");
        display.Rows.Add("Test Row 2", "Test Value  larger line goes here");
        display.Rows.Add("Test Row 3", "Test Value 1");
 
        foreach (var col in display.Columns)
            col.BestFit();
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine("Error Formatting Display: " + ex.ToString());
    }
}

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 09 Oct 2012, 10:50 AM
Hello John,

Thank you for writing.

I am glad to inform you that we are aware of this issue and it is already resolved in our internal builds. You will be able to take advantage of the fix in the upcoming Q3 2012 release, which is due by the end of the next week.

I hope that you find this information useful.

Kind regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
John
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or