Keep hightlight does not work?

Hi, I have the keep hightlight as the following to sort: private void KeepHighLightAfterSorting(MyGridDataBoundGrid grid, object sender, GridCellClickEventArgs e, int lastRowBeforeSorting, string pKey) { int row, col; try { pKey = pKey.Replace(" ", "_"); 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(); // Find a primary string pkCol = string.Empty; string fields = this.adhocParamsVO.PagingFields; if (fields.ToUpper().IndexOf("SSN") > -1) { pkCol = "SSN"; } else if (fields.ToUpper().IndexOf("AIN") > -1) { pkCol = "AIN"; } else { pkCol = this.adhocParamsVO.PagingHeaders.Split('','')[0]; } 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; string colName = pKey; 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); if (dtMain.Rows.Count > 0 && this.adhocParamsVO.HasBreakOrTotal) { this.dtMain.DefaultView.Sort = ""; this.dtMain.DefaultView.Sort = dv.Sort.ToString(); grid.DataSource = this.TotalBreakColumn(dtMain.DefaultView); FormatColumns(fieldInfoList); grid.Refresh(); } //Do what you want to do after the sort, restore the current position //restore current object grid.MySelectionMode = SelectionMode.MultiExtended; int rowIndex = (cm.List as IBindingList).Find(pd, val) + 1; colIndex = grid.CurrentCell.ColIndex + 1; grid.CurrentCell.MoveTo(rowIndex, colIndex); grid.Refresh(); // grid.ScrollCellInView(rowIndex, colIndex); } } catch (Exception ex1) { if (lastRow < 1) { lastRow = 1; } grid.CurrentCell.MoveTo(lastRow, 1); // rowZero = false; // this.NavigatorButton_Click(null, null); if (log.LogError()) { log.Error(ex1.Message); } } } Before running this method, I hightlighted row 10. However, after run this method, a colum is hightlighted instead row 10. Please help!

1 Reply

AD Administrator Syncfusion Team May 18, 2005 02:22 PM UTC

Where are you doing this code? Is it from a CellClick event? Using this code in a CellClick event worked ok for me in 3.2.1.0.
private void gridDataBoundGrid1_CellClick(object sender, GridCellClickEventArgs e)
{
	if(e.RowIndex == 0)
	{
		this.gridDataBoundGrid1.ListBoxSelectionMode = SelectionMode.MultiExtended;
		this.gridDataBoundGrid1.CurrentCell.MoveTo(3,3);
	}
}

Loader.
Up arrow icon