[RESOLVED] [2005] Highlight row in gridview depending on a cell's value
Hey, Just trying to loop through my gridview and change the color of the row if the first cell equals a given value. This is the code I am trying but does not work.
vb Code:
With gvItemList
For i = 1 To .Rows.Count - 1
If .Rows(i).Cells.Item(0).ToString = stValue Then
.Rows(i).BackColor = Drawing.Color.CadetBlue
End If
Next
End With
thanks in advanced!
Re: [2005] Highlight row in gridview depending on a cell's value
Quote:
Originally Posted by Besoup
Hey, Just trying to loop through my gridview and change the color of the row if the first cell equals a given value. This is the code I am trying but does not work.
vb Code:
With gvItemList
For i = 1 To .Rows.Count - 1
If .Rows(i).Cells.Item(0).ToString = stValue Then
.Rows(i).BackColor = Drawing.Color.CadetBlue
End If
Next
End With
thanks in advanced!
Hi,
I think you can try something like this:
Code:
Dim row as DataGridView
Dim genderCell as DataGridViewCell
Dim nameCell as DataGridViewCell
for each row in DataGridView1
genderCell = row.Cells[2] 'gender column
nameCell = row.Cells[0] 'name cell
if CType(gender.Cell.Value, String) = "M" then
nameCell.Style.BackColor = Color.Blue
else
nameCell.Style.BackColor = Color.Pink
end if
next
Hope it helps,
sparrow1
Re: [RESOLVED] [2005] Highlight row in gridview depending on a cell's value
Thanks for the effort... got it with this code:
vb Code:
Dim i As Integer
With gvItemList
For i = 0 To .Rows.Count - 1
If .Rows(i).Cells(0).Text = stValue Then
.Rows(i).BackColor = Drawing.Color.CadetBlue
End If
Next
Re: [RESOLVED] [2005] Highlight row in gridview depending on a cell's value
Quote:
Originally Posted by
Besoup
Thanks for the effort... got it with this code:
vb Code:
Dim i As Integer
With gvItemList
For i = 0 To .Rows.Count - 1
If .Rows(i).Cells(0).Text = stValue Then
.Rows(i).BackColor = Drawing.Color.CadetBlue
End If
Next
Can anyone tell me what gvItemList might be?
Re: [RESOLVED] [2005] Highlight row in gridview depending on a cell's value
Re: [RESOLVED] [2005] Highlight row in gridview depending on a cell's value
Well using this code:
vb Code:
Dim stValue As String
Dim i As Integer
With DataGridView1
For i = 0 To .Rows.Count - 1
If .Rows(i).Cells(0).Text = stValue Then
.Rows(i).BackColor = Drawing.Color.CadetBlue
End If
Next
End With
I'm getting
Error 111 'BackColor' is not a member of 'System.Windows.Forms.DataGridViewRow'.
AND
Error 110 'Text' is not a member of 'System.Windows.Forms.DataGridViewCell'.
Re: [RESOLVED] [2005] Highlight row in gridview depending on a cell's value
looks like you're using vs2003... DataGridView is the earlier version of the Gridview control which is probably why those properties aren't being recognized.
I don't have alot of experience with the older version maybe someone else could help you in this post or you could try making a new one.
Re: [RESOLVED] [2005] Highlight row in gridview depending on a cell's value
Hm..I'm using 2005, maybe I just have the wrong thing :S