ever try setting the color of each dataGridRow independently – based on values within the row’s cells.
The process should be easy enough, but the problem is that you can’t access the methods of the row directly without a bit of work first.

In order to accomplish this, you’ll need to simulate selecting all the dataRows on the dataGridView grid. (That’s also not trivial to do – as grid.selectAll() seems to be selecting a reference or in-memory copy of the rows … not the actual rows.)

One way would be to add all the rows to an arrayList — but this step isn’t necessary if you allow the user to manually multi-select the rows. doing that, actually does allow you to programatically run through all (manually selected) rows with grid.selectedRows(). Baring that, I’m fairly convinced that you have to get a bit tricky to accomplish the task.

the second part deals with changing the back-color and fore-color on the dataGridViewRow.

Here’s a hint.

for each dgvr as datagridviewrow in grid.selectedRows
Dim drv As DataRowView
drv = dgvr.DataBoundItem
Dim dr as dataRow = drv.Row
‘do stuff
next

From that point on, you can refer the value of the elements by datarow and do some pretty neat stuff.

2 Responses to “vb.net, selecting data rows and setting datagridview row color”


  1. [...] setting dataGridRow color at runtime [...]


  2. que buena ayuda gracias


Leave a Reply