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

DataboundGrid BeginUpdate is not suspending painting in custom sorting

Hi, In my databound grid, when the user double clicks on a column, I want to use my own custom sorting method. So I created a hidden column "SortOrder" and changing the values in that column everytime the user double clicks on a col header. After that I use currencymanager and bindinglist to sort it. In the attached sample, I have derived from DataboundGrid( VS.NET 2003) and it has datatable (which is part of a dataset) as the datasource. I have overridden the SortColumn(int colIndex) method from base class. I cut/pasted SortField() code from the Syncfusion databound grid. I commented out BinderSort(fieldNum) and added my sorting logic there. In my sorting logic, I am updating DataRow["SortOrder"] values. Run the attached sample, keep double clicking on the name column to see the values scrolling. I want to suppress the painting until sorting is completed. Eventhough I have BeginUpdate() and EndUpdate() around my code, why is the grid painting? Also, Is there anyway to show the sort icon on current column header even though I am sorting on "SortOrder" column? thanks, - Reddy

3 Replies

AD Administrator Syncfusion Team October 3, 2003 03:47 PM UTC

Call SuspendBinding after BeginUpdate and ResumeBinding after EndUpdate: /// public override void SortColumn(int colIndex) { bool hasCC = CurrentCell.HasCurrentCell; //int colIndex = CurrentCell.ColIndex; BeginUpdate(); this.Binder.SuspendBinding(); try { int fieldNum = this.Binder.ColIndexToField(colIndex); Console.WriteLine("Customer Sorting fieldNum = " + fieldNum); if (CommitChanges()) { CollapseAll(); //Binder.Sort(fieldNum); // use custom sorting string fieldName = this.Binder.InternalColumns[fieldNum].MappingName; DataTable table = this.DataSource as DataTable; SortTable(fieldName, table, GetSortDirection()); Selections.Clear(); Refresh(); if (hasCC) { CurrentCell.MoveTo(Binder.CurrentRowIndex, colIndex); } } } finally { this.Binder.ResumeBinding(); EndUpdate(); } } BTW - I recently worked on a similar example so that you can sort a databound grid with the foreign key of a combobox displaymember. I'll attach it although it looks like you already got it working your way. But maybe it still helps. Stefan

AD Administrator Syncfusion Team October 3, 2003 07:17 PM UTC

Stefan, Thank you very much for your reply. Now my painting problem is gone. I have a complex tree sorting that can not be done using the datasource technique you mentioned above. How can I show the little sort direction icon in my header cell on which the user double clicked (even through I am actually sorting based on a hidden column 'SortOrder')? I tried setting this[0, curColIndex].Tag = ListSortDireciton.Ascending. It does not work. thanks, - Reddy

AD Administrator Syncfusion Team October 3, 2003 08:33 PM UTC

You need to do that in QueryCellInfo. Check out the QueryCellInfo code in the sample. You should do something similar. Stefan

Live Chat Icon For mobile
Up arrow icon