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

Color Ragdrid row at will without Row or Cell Formatting Event Handler

2 Answers 154 Views
GridView
This is a migrated thread and some comments may be shown as answers.
code777
Top achievements
Rank 1
code777 asked on 19 Apr 2013, 10:54 AM
I would like to change the BackColor a datagridview row. While searching around it 's clear that I will have to access the GridDataRowElement or GridDataCellElement to do it. From that  after creating a variable of the type  we can call something  RowElement.BackColor = Color.Gray or CellElement.BackColor = Color.Gray

I have already tried this but it only colors row while the mouse is hovering at it (very strange...)
Dim rwInfo As GridViewRowInfo = myGrid.Rows(i)
myGrid.GridViewElement.TableElement.GetRowElement(rwInfo).BackColor = System.Drawing.Color.PaleGoldenrod


Now with the code below as a pointer, my problem is that I'm trying to cast a gridview row as GridDataRowElement it always results in epic failure.


For i = 0 To myGrid.Rows.Count - 1
Dim r As GridViewRowInfo = myGrid.Rows(i)
Dim rwInfo As GridViewRowInfo = myGrid.Rows(i)
For Each cInfo As GridViewCellInfo In rwInfo.Cells
Dim row As GridDataRowElement = TryCast(myGrid.Rows(i), GridDataRowElement)
Next
  For Each c In myGrid.Columns
Dim cell As GridDataCellElement = CType(rwInfo.Cells(c.Index), GridDataCellElement)
Next
Next


Could someone please point me to the right direction on how this can be done?

Thanks

2 Answers, 1 is accepted

Sort by
0
code777
Top achievements
Rank 1
answered on 23 Apr 2013, 09:13 AM
Well, the answer was steering at me in the face all along. I had to use the RowFormatting event to colour a particular row if that row's particular cell value satisfies some condition.
And then just simply subscribe to the same event any where in  the code every time you want to colour another row.
0
Accepted
Stefan
Telerik team
answered on 24 Apr 2013, 07:25 AM
Hello,

Thank you for writing.

That is correct, in order to change the appearance of rows you should use the RowFormatting event and for cells the CellFormatting event. Please refer to the following articles for more information:
I hope that you find this information useful
 

All the best,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
GridView
Asked by
code777
Top achievements
Rank 1
Answers by
code777
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or