Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15819

VS 2019 Colouring DGV rows depending on it's contents.

$
0
0
Hello!

I'm trying to color the rows in my DataGridView by groups, all rows with the same date will be one color, then the next group with the same date will be a different color, something like this:
Name:  DGV.jpg
Views: 129
Size:  54.5 KB

The real data in my table is this:
Name:  Tabla.jpg
Views: 40
Size:  38.1 KB

In another post a nice member on this forum explain to me the steps to achieve the goal, he even help me with most of the task sharing the following code.

VB:NET Code:
  1. Dim distinctValues = DataGridView1.Rows.
  2.                                Cast(Of DataGridViewRow)().
  3.                                Select(Function(row) CStr(row.Cells("Hora_para_cancelar").Value)).
  4.                                Distinct().
  5.                                ToArray()
  6.                 Dim allColors = {Color.Yellow, Color.Blue}
  7.                 Dim colorsByDate As New Dictionary(Of String, Color)
  8.  
  9.                 For i = 0 To distinctValues.GetUpperBound(0)
  10.                     colorsByDate.Add(distinctValues(i), allColors(i))
  11.                 Next

But I'm getting this error in line 10:
System.IndexOutOfRangeException: 'Índice fuera de los límites de la matriz.
Help please!
Attached Images
   

Viewing all articles
Browse latest Browse all 15819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>