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

3 posts, 1 answers
  1. code777
    code777 avatar
    2 posts
    Member since:
    Feb 2013

    Posted 19 Apr 2013 Link to this post

    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. code777
    code777 avatar
    2 posts
    Member since:
    Feb 2013

    Posted 23 Apr 2013 Link to this post

    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.
  3. Answer
    Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 24 Apr 2013 Link to this post

    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.
Back to Top