cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement this kind of color banding?

leon_laikan
Participant
0 Kudos

Hi, everybody

We are working on a SDK add-on, and are using Visual Basic.NET.

We have generated a grid which derives its data from a Query.

We want to colour the rows (in a special way) to facilitate reading the data on the grid.

Please see the picture.

Anybody has an idea how to implement this kind of colour banding?

Thanks

Leon Lai & Team

Accepted Solutions (1)

Accepted Solutions (1)

Johan_H
Active Contributor
0 Kudos

Hi Leon Lai,

You could simply loop through the rows and assign a new color to the row each time IT ref changes.

However there are two questions you need to ask yourself:

  1. What should happen to the color coding when the user sorts the table by another column than IT ref ?
  2. Do you want to use two colors or a separate color per different IT ref value ?

Regards,

Johan

leon_laikan
Participant
0 Kudos

Hi, Johan

Thanks a lot for your reply.

I have successfully implemented simple alternating colour banding in previous projects (sort of Red - Blue - Red - Blue - etc) based on row number only. If row number is even, then red. If row number is odd, then blue.

But this problem is more complex and I have no idea how to solve it.

To answer your questions:

1.  User will not be required to do any sorting. Sorting has already been done by my query.

2. I prefer to use 2 colours only (say red and blue). Too many colours can be ugly.

Hope this can help.

Best Regards,

Leon

edy_simon
Active Contributor
0 Kudos

Hi Leon,

Roughly :

Dim LastColour as String = Red

Dim LastITRef as String = ""

For i as integer  = 0 to oGrid.Rows.Count -1

     Dim CurrentRowITRef as String = oGrid.DataTable.Rows.GetValue("col", oGrid.GetDataTableRowIndex(i)).ToString.Trim

     If LastITRef = CurrentRowITRef then

          'Set Current Row to LastColur.

     Else

          If LastColur = Red Then

               'Your code to set Current Row as Blue here


                 LastColour = 'Blue'        

          Else

               'Your code to set Current Row as Red here

               LastColour = 'Red'

          End If

          LastITRef = CurrentRowITRef

        

     End If

Next

Regards

Edy

Johan_H
Active Contributor
0 Kudos

Hi Leon,


Leon Lai Kan wrote:

...

1.  User will not be required to do any sorting. Sorting has already been done by my query.

...

The problem is usually that the user will try do things anyway, even though they are not required or supposed to. So what I meant is, once you implement a solution, like the one Edy Simonsuggested, and the user sorts the table on another column, what will happen ? Or will you lock the table so the user cannot sort it ?


Leon Lai Kan wrote:

...

2. I prefer to use 2 colours only (say red and blue). Too many colours can be ugly.

...

Edy Simon's suggestion should work nicely, but you should still consider question 1.


Regards,

Johan

leon_laikan
Participant
0 Kudos

Hi Edy,

I have tested your suggestion.

Unfortunately, it did not work at first.

We spent a few hours debugging it, and found what did not work:

When I replaced this line:

Dim CurrentRowITRef As String = "Grid.DataTable.Rows.GetValue("IT Ref", i).ToString

by this one:

Dim CurrentRowITRef As String= Grid.DataTable.GetValue("IT Ref", i).ToString

then your code works perfectly!

It's great!

Thanks again for your generous help.

Best Regards,

Leon

leon_laikan
Participant
0 Kudos

Hi Johan,

Thanks again for your reply.

There may be cases where the user is required to interact with the grid. But, in this present situation, my grid is a final report that does not necessitate any user intervention. It all depends on design.

Thanks for your time, and Best Regards,

Leon

edy_simon
Active Contributor
0 Kudos

Hi Leon,

Sorry for that, I did the code on the fly and did not test it first.

Just to give you the basic idea.

Regards

Edy

Answers (0)