• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 515
  • Last Modified:

VSTO - DataGRidView change line colour on click

Hi

In a DataGridView is it possible using VB.net code to change the row color,
0
Murray Brown
Asked:
Murray Brown
  • 2
1 Solution
 
nepaluzCommented:
handle the click event and set the row color by

Dim MyGrid =DirectCast(Sender, DataGridView)
MyGrid.Rows(e.RowIndex).BackColor=Color.Blue

Open in new window

0
 
mayank_joshiCommented:
use this code after setting the datasource on DataGridView:-

For Each dgvr As DataGridViewRow In myDGV.Rows
	If dgvr.Cells(0).Value < dgvr.Cells(1).Value Then    ' You may have some other condition
		dgvr.DefaultCellStyle.ForeColor = Color.Red
                dgvr.DefaultCellStyle.BackColor = Color.Yellow
            
	End If
Next

Open in new window

0
 
mayank_joshiCommented:
here myDGV is the ID of the DataGridView
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks very much
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now