How to set default collation on DevExpress GridView

In .net WinForm, DevExpress GridControl / GridView is bound to DataSet, how to specify default sort order? One that is used when there is no visible GridColumn with SortOrder.

By default, I set the sort in the view on my hidden DateTimeStamp GridColumn column. It, of course, is redefined by the user if the user clicks on a column. The user can "Clear Sort" by using the menu in the column or by clicking on the column by pressing the "Control" key. However, the strings are not sorted anymore (or maybe PK?), While I would like them to be sorted by DateTimeStamp.

Any idea? Maybe by connecting a notification code when the user is "Clear Sorting"? I can play with GridView.PopupMenuShowing and GridStringId.MenuColumnClearSorting to handle the case with a menu click. But it does not handle the Control + click case.

Does someone encounter the same problem and find a (simple) solution?

+3
source share
5 answers

If I were you, I would sort the DataSource grid based on the required column. In this case, if the gridView sort condition is cleared by the end user, the data will be displayed in the order specified by your data source.

UPDATE here is the code that should work for you:

DataView dv = yourDataTable.DefaultView;
dv.Sort = "SomeField";
gridControl.DataSource = dv;

Also, check out the following MSDN article:

Property DataView.Sort

+2

? - , ?

+1

Just put this after InitializeComponent();in the constructor

GridView1.Columns["FieldName"].SortOrder = ColumnSortOrder.Ascending;
+1
source

You can add an event handler to the event GridView.EndSorting, and in this handler check if there are any columns with SortIndex >= 0. If not, you can set up your own sorting.

0
source

GridControl.SortBy (DateTimeStampColumn, ColumnSortOrder.Descending);

-3
source

All Articles