I am trying to sort a column with this code
' sort based on the percentage difference column, defaulting to worst performers first. e.Layout.Bands(0).Columns(4).SortIndicator = SortIndicator.Ascending e.Layout.Bands(0).Columns(4).InitialSortDirection = SortDirection.Ascending e.Layout.Bands(0).SortedColumns.RefreshSort(True)
I also tried putting the code in later, after I populated the table:
UltraGrid1.DataSource = dtCache ' sort based on the percentage difference column, defaulting to worst performers first. UltraGrid1.DisplayLayout.Bands(0).Columns(4).SortIndicator = SortIndicator.Ascending UltraGrid1.DisplayLayout.Bands(0).SortedColumns.RefreshSort(True)
I added iniitialsortdirection because sortindicator didn't seem to be sorting (it is setting the indicator), but to no avail. Essentially, the column sort indicator is set, but the column is NOT sorting until I click on the column header. I am trying to do in code the equivalent of manually clicking on the column heading, to initiate a sort.
Thanks.
I've added this code. If I click either radio button, it works fine, but if I call SortTheGrid right after populating the grid, it is not working. The data is not sorted. What am I doing wrong? P.S. this is an unbound grid: I am setting the data source to a data table at run time.
Private Sub RB_WORST_CheckedChanged(sender As Object, e As EventArgs) Handles RB_WORST.CheckedChanged If Not (InitialLoad) Then SortTheGrid() End If End Sub
Private Sub RB_BESTS_CheckedChanged(sender As Object, e As EventArgs) Handles RB_BESTS.CheckedChanged If Not (InitialLoad) Then SortTheGrid() End If End Sub
Private Sub SortTheGrid() If RB_BESTS.Checked = True Then UltraGrid1.DisplayLayout.Bands(0).Columns(4).SortIndicator = SortIndicator.Descending Else UltraGrid1.DisplayLayout.Bands(0).Columns(4).SortIndicator = SortIndicator.Ascending End If UltraGrid1.DisplayLayout.Bands(0).SortedColumns.RefreshSort(True) End Sub
Hi Samuel,
How are you populating the grid? If you simply set the grid's data source and then set the SortIndicator, then my expectation is that the grid would be sorted. Are you able to provide a sample application that I can use to debug for you? If you would prefer not to share the sample on the forum, please let me know and I will open a private case for you.
Here's the code:
Private Sub DoTheThing() Try ' reset both grids UltraGrid1.DataSource = Nothing UltraGrid2.DataSource = Nothing Catch ex As Exception End Try Me.Cursor = Cursors.WaitCursor UseWaitCursor = True Application.DoEvents() Threading.Thread.Sleep(100) 'WAITING FOR THE CODE TO FINISH Dim s_SQL As String = "" DrillLevel = 1 Try Grid1_Caption = "" Construct_SQL(SQLstmt) Try dsCache2.Tables(0).Rows.Clear() Application.DoEvents() Threading.Thread.Sleep(100) 'WAITING FOR THE CODE TO FINISH Catch ex As Exception End Try cnCache = New CacheConnection("Server = xx.xx.xx.xx; Log File=cprovider.log;Port=1972; Namespace=TEST; Password = TEST; User ID = TEST;") cnCache.Open() dsCache = New DataSet() daCache = New CacheDataAdapter ' daCache.SelectCommand = New CacheCommand(SQLstmt, cnCache, txCache) daCache.Fill(dsCache, "Sample_Person") dtCache = dsCache.Tables("Sample_Person") UltraGrid1.DataSource = dtCache InitialLoad = False SortTheGrid() UltraGrid1.Text = Grid1_Caption Catch eLoad As Exception MessageBox.Show("An error has occurred: " + eLoad.Message) Application.Exit() End Try UseWaitCursor = False Me.Cursor = Cursors.Default Application.DoEvents() End Sub
Focusing on the creation and setting of the data source, it appears to me that the data should be sorted properly. However, I do notice some threading code in there and I'm not certain what it's doing or whether it's affecting the UI.
If you can provide a sample application, I can debug this further. If you are unable to reproduce this in a sample, I would suspect that some other code in the application is impacting the grid in a way that prevents it from being able to see the data at the time it tries to sort.
How shall I provide you with a sample? I've never done that before.
commented out the threading code. No change in behavior.
You can zip the sample and attach it to a reply here on the forum. If you would prefer not to upload the sample publicly, just let me know and I'll open a private case where you can send it to me directly.
I'd rather open a private case, thanks.