Results 1 to 2 of 2

Thread: [2005] Datagridview rowprepaint?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    [2005] Datagridview rowprepaint?

    Hi!

    I have an issue I cant find a solution for.

    In ASP.NET it is extremly easy to change a row/cell at databind time depending on what the value is.

    I was very surprised that I didnt find such similar events for the datagridview. I did find the rowprepaint event but I am not sure it is suited for the task
    The info I need is

    column, row and value to bind


    kind regards
    Henrik

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Datagridview rowprepaint?

    Yes, you can handle the DGV.RowPrePaint event to color the row/cells conditionally. Something like this:
    Code:
    Private Sub DataGridView1_RowPrePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint
            Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
            Dim cellValue As Object = row.Cells(0).Value
            If cellValue IsNot Nothing AndAlso cellValue.ToString.StartsWith("something") Then
                row.DefaultCellStyle.BackColor = Color.Yellow
            End If
        End Sub
    Is it best suited for the task? I don't know, but it works.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width