If I've coloured the rows of my grid using 'PrepareViewStyleInfo' and then sort the grid by clicking on the column header the data is sorted, but the rows remain colour as before the sort.
(If i'm colouring on row content the colouring makes no sense now)
How do I detect a sort has taken place so I can re-colour my rows?
ADAdministrator Syncfusion Team March 12, 2003 04:13 AM
I am not sure I full understand.
Did you implement alternating colouring for rows in PrepareViewStyleInfo.
When you sort the colouring should be indepenent of the original row index and simply still alternate for each row.
Or do you want to have colors based on the original row index in the datasource?
You are referring to databoung grid, correct?
To detect if a Sort happened, you have to check the underlying IBindingList of the datasource. This has a SortProperty which returns the PropertyDescriptor of the sorted column.
You can get the datasource/IBindingList usually with following code: this.BindingContext[dataSource, dataMember];
ADAdministrator Syncfusion Team March 12, 2003 04:16 AM
Using PrepareViewStyleInfo means that the colors are dynamically set any time the grid is drawn. Since sorting will redraw the grid, the colors would have been reset also at this point.
Normally, when handling PrepareViewStyleInfo, and setting the BackColor there based on some condition tied to the values in the e.RowIndex passed in, sorting should not affect this condition and the colors should 'stick' with the particular values in the in the row, e.RowIndex. Now if your condition that sets the color depends upon a different row, or is not actually dependent upon the cell values in that row (say coloring all odd rows), then the colors would not stick.
Exactly how are you determining the color in PrepareViewStyleInfo?
MWMike WeaverMarch 12, 2003 05:01 PM
I'm not getting the colouring to move with the data. It stays static.
This is the code:...
Private Sub GridDataBoundGrid1_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs) Handles gdGrid.PrepareViewStyleInfo
Dim iRow As Integer = e.RowIndex
If iRow <= dsData.Tables(0).Rows.Count Then
If dsData.Tables(0).Rows(iRow).Item("colourBy") = "Colour1" Then
e.Style.BackColor = Color.Yellow
ElseIf dsData.Tables(0).Rows(iRow).Item("colourBy") = "Colour2" Then
e.Style.BackColor = Color.Green
ADAdministrator Syncfusion Team March 13, 2003 01:13 AM
The reason is that you are checking the value in the datatable. The order of the data in the datatable does not move when it is sorted. So, the colorBy value in row xxx will always be in row xxx. If does not move. So, your colors do not move either.
So instead of accessing the test item through the table with code like dsData.Tables(0).Rows(iRow).Item("colourBy") , try getting it from the DefaultView on the table with code like dsData.Tables(0).DefaultView(iRow).Item("colourBy")
MWMike WeaverMarch 13, 2003 06:22 PM
This makes no difference.
The row colouring is still static.
MWMike WeaverMarch 13, 2003 07:25 PM
What i guess I really need is info on doing a reverse lookup on the data rows from the datagrid?
ADAdministrator Syncfusion Team March 14, 2003 01:49 AM
As far as reverse lookups, wouldn't you need to do the reverse lookup in your datatable and not the grid? As I understand it, there is no color column in the grid to look for. (Now one approach might be to add such a column, and hide it. Then you could use this grid column to get the color.)
Attached is a sample that I think is what you are describing. You have a column in a datatable that holds a color (and is not displayed in teh grid). You want to use this color to color the row in grid.
In the sample, when you sort the columns, the color rows move in sync. There is also a Filter button that filters the datasource, and after filtering, the row color still sync up when sorted.
If the sample works when you try it, what is different about what you are doing?
MWMike WeaverMarch 18, 2003 10:20 PM
Clay example app worked fine.
but i'm doing _exactly_ the same thing you are.
Is there any variable or options that I may have set to prevent/cause this behaviour?
ADAdministrator Syncfusion Team March 19, 2003 02:39 AM
You might check to see if something is throwing an exception that might be interfering with things. Use the Debug|Exceptions menu item to set Common Language Rutime exceptions to 'Break into the debugger' when they are hit.
Also, maybe you could spot something by putting some debug output in the PrepareViewStyleInfo event to trace the execution paths and display values to see if they make sense. (Note this event is hit a lot, so you'll see lots of output from any debug output you have here).
If you can post a sample showing the problem (or create a Direct Trac support incident and post it there), we can see if we can spot the problem here.