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.
Unfortunately, activation email could not send to your email. Please try again.

How to keep the highlight of a record after sorting (by double-click on every header)?

Thread ID:

Created:

Updated:

Platform:

Replies:

25207 Feb 22,2005 03:31 AM Apr 4,2005 03:55 AM Windows Forms 7
loading
Tags: GridControl
David Bosak
Asked On February 22, 2005 03:31 AM

Hi, I have a table with 10 columns. SSN (Social Security Number) is one of them. Before sorting, the record which has SSN=000-00-0020, is being highlighted. However, after sorting, highligh is at the first record instead of SSN=000-00-0020. How does SSN=00-00-0020 still keep the highlight? Thank a lot!

Administrator [Syncfusion]
Replied On February 22, 2005 04:57 AM

You will have to handle this yourself, saving the selected row before the sort, and resetting it after the sort somehow. Here is a forum thread that discusses this. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=10655

Administrator [Syncfusion]
Replied On February 22, 2005 01:50 PM

Clay, What would be the way when the PK has more than one column? Regards, Thomas >You will have to handle this yourself, saving the selected row before the sort, and resetting it after the sort somehow. Here is a forum thread that discusses this. > >http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=10655

Administrator [Syncfusion]
Replied On February 22, 2005 02:20 PM

There may be a better way, but here is one way that I think would work. Get the DataView from the grid''s CurrencyManager, and directly loop through the DataView looking for the row with the right primary keys. Looping through the DataView will be much faster than looping through the grid itself as it avoids the grid events required to retrieve the data. Once you have the position in the CUrrencyManager, you can use grid.Binder.PositionToRowIndex to get the proper row. To get the DataView, you can use CurrencyManager cm = (CurrencyManager)this.grid.BindingContext[grid.DataSource, grid.DataMember]; DataView dv = (DataView) cm.List; //loop through dv looking for PK values //

David Bosak
Replied On February 23, 2005 02:20 AM

Thanks a lot, it worked... I also corrected some lines for my codes: copyGrid.SortBehavior = GridSortBehavior.None; then call the method: private void KeepHighLightAfterSorting(MyGridDataBoundGrid grid, object sender, GridCellClickEventArgs e, int lastRowBeforeSorting) { int row, col; grid.PointToRowCol(new Point(e.MouseEventArgs.X, e.MouseEventArgs.Y), out row, out col, -1); if(row == 0 && col > 0) { //Save the current position CurrencyManager cm = (CurrencyManager) this.BindingContext[grid.DataSource, grid.DataMember]; PropertyDescriptorCollection pdc = cm.GetItemProperties(); string pkCol = "SSN"; //assumes Col1 is primary key column PropertyDescriptor pd = pdc.Find(pkCol, true); int colIndex = grid.Binder.NameToColIndex(pkCol); object val = grid[lastRowBeforeSorting, colIndex].Text; //primary key value on teh current row //Do the sort, assumes datasource is a DataTable DataTable dt = (DataTable) grid.DataSource; DataView dv = dt.DefaultView; GridBoundColumn gbColumn = grid.GridBoundColumns[col - 1]; string colName = gbColumn.MappingName; ListSortDirection sd = ListSortDirection.Ascending; if(grid[row, col].Tag != null) { sd = (ListSortDirection)grid[row, col].Tag; } string sdString = (sd == ListSortDirection.Ascending) ? "Desc" : "Asc"; dv.Sort = string.Format("{0} {1}", colName, sdString); //Do what you want to do after the sort, restore the current position //restore current object int rowIndex = (cm.List as IBindingList).Find(pd, val) + 1; colIndex = grid.CurrentCell.ColIndex; grid.CurrentCell.MoveTo(rowIndex, colIndex); grid.ScrollCellInView(rowIndex, colIndex); } }

Administrator [Syncfusion]
Replied On April 4, 2005 12:01 AM

However, how will we do if one grid has no any primary key? Please help! Thanks

David Bosak
Replied On April 4, 2005 12:08 AM

However, how will we do if one grid has no any primary key? Please help! Thanks

Administrator [Syncfusion]
Replied On April 4, 2005 03:55 AM

You will have to do somethiing to find the new current record. Without special information like a primary key, then worse case, you could loop through the DataRowView.Row''s in the DataView looking for the saved current DataRow. Note, you would not want to loop through the grid to do this. This will be slower as the grid has to get the data from the DataView. You can find the position of the saved DataRow in the DataView working only through the DataView, and then use grid.Binder.PositionToRowIndex to find the rowIndex in the grid. (If you use a GridGroupingControl instead of a GridDataBoundGrid, the current record will be moved through any sorts, and you do not have to do this additional work.)

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.

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.

;