|
-
Oct 10th, 2007, 12:57 PM
#1
Thread Starter
Frenzied Member
[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!
-
Oct 10th, 2007, 02:55 PM
#2
Re: [2005] Highlight row in gridview depending on a cell's value
 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
-
Oct 11th, 2007, 10:14 AM
#3
Thread Starter
Frenzied Member
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
-
Jul 22nd, 2009, 02:51 PM
#4
Hyperactive Member
Re: [RESOLVED] [2005] Highlight row in gridview depending on a cell's value
 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?
Tuber
"I don't know the rules"
-
Jul 27th, 2009, 09:55 AM
#5
Thread Starter
Frenzied Member
Re: [RESOLVED] [2005] Highlight row in gridview depending on a cell's value
-
Jul 27th, 2009, 10:02 AM
#6
Hyperactive Member
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'.
Tuber
"I don't know the rules"
-
Jul 27th, 2009, 10:16 AM
#7
Thread Starter
Frenzied Member
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.
-
Jul 27th, 2009, 10:24 AM
#8
Hyperactive Member
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
Tuber
"I don't know the rules"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|