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. Image for the cookie policy date
close icon

Grid Column Sorting

I noticed a post where Clay mentioned that column sorting works in the grid with a dbl-click and that it can easily be implemented as a single click. Is there a sample of how to implement column sorting and displaying a visual indicator for the sorted column (like the up/down arrow)? I am essentially trying to replace the listview with an improved, databound, column sorting control that has a visual indicator in the header. Is the Grid even the best option? Thanks in advance. Anthony Mansfield

7 Replies

CB Clay Burch Syncfusion Team June 27, 2002 10:15 AM UTC

> I noticed a post where Clay mentioned that column sorting works in the grid with a dbl-click and that it can easily be implemented as a single click. > > Is there a sample of how to implement column sorting and displaying a visual indicator for the sorted column (like the up/down arrow)? > > I am essentially trying to replace the listview with an improved, databound, column sorting control that has a visual indicator in the header. Is the Grid even the best option? > > Thanks in advance. > > Anthony Mansfield If you use the GridDataBoundGrid class for your databound grid, then there is a SortBehavior property that you can set to select either no sorting, single-click sorting or double-click sorting. For a GridControl class, sorting is not directly supported in this 1.0 release, but will be supported in a later release. You can, however, catch the click on a column header, and implement Sort behavior yourself. It would take some coding...


SH Sam Horton June 27, 2002 03:27 PM UTC

I think we're basically after the same thing -- a better listbox with full binding/control. I've noticed that if I invoke the following code for the databound grid that the sort behavior is disabled: Me.dGrid.ListBoxSelectionMode = SelectionMode.One


AM Anthony Mansfield June 27, 2002 05:24 PM UTC

I agree with Sam, it seems like we have stumbled onto a gap in what is currently available. VS.NET ListView - Provides sorting capabilities w/o databinding or a visual sort indicator in the column header. VS.NET DataGrid - Provides databinding, sorting and a visual sort indicator but limited field types and display formatting options. Hmmm...Seems like we are defining an opportunity for a tools vendor. I am curious what control Microsoft is using when it displays search results (similiar to Outlook Advanced Find Feature). The control looks like a listview, with columns sorting and visual sort indicators. When your trying to build apps that look and act like existing apps it gets kind of tough when the controls don't quite act the same. Anthony Mansfield


SH Sam Horton June 27, 2002 06:07 PM UTC

We're on the same exact track; builing an app which looks/feels like Outlook 2002 -- Advanced find, quickfind, solid listboxes, similar toolbar look/feel etc... I may end up using UltimateGrid and just hand-coding every little thing..... (ugh!) On toolbars it is a bit better, but trying to get an outlook-style toolbar item which handles: [context item][arrow] is proving a challenge...


CB Clay Burch Syncfusion Team June 27, 2002 07:09 PM UTC

The problem with singleselectionmode locking out sorting in GridDataBoundGrid will be handled before the final release. The reason for this lock out is that the single row selection mode turns off the other selection options like column selections which are where the sorting is hooked. The solution will be to handle the singleselectionmode in the same manner as the GridListControl which allows for column selections. In the mean time, you can still sort with single select mode by handling the mousedown event in the GridDataBoundGrid, and call the sort routine if the click is on a column header. Here is a code snippet. private void gridDataBoundGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { int row, col; if(this.gridDataBoundGrid1.PointToRowCol(new Point(e.X, e.Y), out row, out col) && row == 0 && col > 0) this.gridDataBoundGrid1.SortColumn(col); }


AM Anthony Mansfield June 28, 2002 02:31 AM UTC

Here is a sample of a VB.NET form with a list view that has full row select, column sorting and a visual sort indicator. It took some research and a couple of work arounds but it seems to be working pretty well. This seems to be a common request, so I thought I would share it.


SH Sam Horton June 29, 2002 01:24 AM UTC

Wow. That's great! Thank you!

Loader.
Live Chat Icon For mobile
Up arrow icon