We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Column sorting & row colouring

Thread ID:

Created:

Updated:

Platform:

Replies:

3295 Mar 12,2003 04:19 AM UTC Mar 19,2003 07:39 AM UTC WinForms 9
loading
Tags: GridControl
Mike Weaver
Asked On March 12, 2003 04:19 AM UTC

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?

Administrator [Syncfusion]
Replied On March 12, 2003 09:13 AM UTC

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]; Stefan

Administrator [Syncfusion]
Replied On March 12, 2003 09:16 AM UTC

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?

Mike Weaver
Replied On March 12, 2003 10:01 PM UTC

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 End If End If End Sub

Administrator [Syncfusion]
Replied On March 13, 2003 06:13 AM UTC

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")

Mike Weaver
Replied On March 13, 2003 11:22 PM UTC

This makes no difference. The row colouring is still static. Nuts.. ;(

Mike Weaver
Replied On March 14, 2003 12:25 AM UTC

What i guess I really need is info on doing a reverse lookup on the data rows from the datagrid?

Administrator [Syncfusion]
Replied On March 14, 2003 06:49 AM UTC

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?

Mike Weaver
Replied On March 19, 2003 03:20 AM UTC

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? TIA Mike.

Administrator [Syncfusion]
Replied On March 19, 2003 07:39 AM UTC

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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;