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

Problem setting background color of a row

3 Answers 205 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hilda Kenny
Top achievements
Rank 1
Hilda Kenny asked on 16 Aug 2010, 02:08 PM
hi,
I recently upgraded to 2010 Q2 and since then I get an error: 'Object Reference not set to an instance of an object' on this line:

e.RowElement.BackColor =

CType(_colourConvert.ConvertFromString(e.RowElement.RowInfo.Cells(_StatusColour).Value().ToString), System.Drawing.Color)

 


Any help would b appreciated.

3 Answers, 1 is accepted

Sort by
0
Eric
Top achievements
Rank 1
answered on 16 Aug 2010, 06:19 PM

You are obviously in a grid event since you are referencing e as an event args. I'm assuming the RowFormatting event?? Anyway, what object is nothing? If you put a breakpoint in the event and start dragging the objects into the watch window you should see which object is nothing. You can also add code above the line like

if(Not(e is nothing)) then
   If(Not(e.RowElement is Nothing)) Then
       If(Not(e.RowElement.RowInfo is Nothing)) Then
          If(Not(e.RowElement.RowInfo.Cells(_StatusColour) is Nothing)) Then
              If(Not(.RowElement.RowInfo.Cells(_StatusColour).Value is Nothing)) Then
                     e.RowElement.BackColor =

                           CType(_colourConvert.ConvertFromString(e.RowElement.RowInfo.Cells(_StatusColour).Value().ToString), System.Drawing.Color)

             End if
        End if
       End if
     End if
End if

That should stop the error but you still might be missing the functionality do to your BackColor will not be set when one of those objects is null. If you find the object that is nothing by checking it in the watch you can just add that corresponding above if statement

Eric
0
Stefan
Telerik team
answered on 19 Aug 2010, 04:13 PM
Hello everyone,

Thank you for writing.

@Hilda
I would suggest you to take a look at this blog post which you might find helpful when working with RowElement and CellElement.

As to your question regarding changing the backcolor, please subscribe for the RowFormatting event and add the following code snippet:

void radGridView1_RowFormatting(object sender, Telerik.WinControls.UI.RowFormattingEventArgs e)
        {
            int indexOfMyFavoriteRow = 2;
            if (e.RowElement.RowInfo.Index == indexOfMyFavoriteRow)
            {
                e.RowElement.DrawFill = true;
                e.RowElement.BackColor = Color.Red;
                e.RowElement.BackColor2 = Color.Red;
                e.RowElement.BackColor3 = Color.Red;
                e.RowElement.BackColor4 = Color.Red;
            }
 
        }

I hope you find this information helpful. If there is anything else we can help you with, do not hesitate to contact us.

All the best,
Stefan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Hilda Kenny
Top achievements
Rank 1
answered on 20 Aug 2010, 04:57 PM
I'll have a look, thanks.
Tags
GridView
Asked by
Hilda Kenny
Top achievements
Rank 1
Answers by
Eric
Top achievements
Rank 1
Stefan
Telerik team
Hilda Kenny
Top achievements
Rank 1
Share this question
or