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

v3.2.1.0 weird tab behavior

We have upgraded to v3.2.1.0 and I noticed this weird tab behavior in enabled cells/range. The tab key is treated as a valid cell entry. Steps to re-create the prob: 1. add a grid to a project and add the code below 2. keep tabbing until the last enabled row (last enabled row is a range). When your at the last row, tab is treated as a tab entry, not a TAB key. 3. same thing happens for shift-tab and 1st row. code ---- private void Form1_Load(object sender, System.EventArgs e) { GridStyleInfo cell; GridControl grid = gridControl1; // show/hide row/col headers grid.Rows.Hidden[0] = true; grid.Cols.Hidden[0] = true; grid.TabStop = true; grid.WantTabKey = true; grid.Model.Options.WrapCellBehavior = GridWrapCellBehavior.NextControlInForm; // grid.Model.Options.ActivateCurrentCellBehavior = GridCellActivateAction.SelectAll; // Optional: grid.Model.Options.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.GrayWhenLostFocus; // disable grid cell = grid.TableStyle; cell.Enabled = false; //enable some cells cell = grid[2,1]; cell.Format = "P2"; cell.BackColor = Color.LightGoldenrodYellow; cell.Text = "enabled1"; cell.Enabled = true; cell = grid[3,4]; cell.Format = "P2"; cell.BackColor = Color.LightGoldenrodYellow; cell.Text = "enabled1"; cell.Enabled = true; cell = grid[4,4]; cell.BackColor = Color.LightGoldenrodYellow; cell.Text = "enabled2"; cell.Enabled = true; cell = grid[4,1]; cell.Format = "P2"; cell.BackColor = Color.LightGoldenrodYellow; cell.Text = "enabled1"; cell.Enabled = true; cell = grid[5,4]; cell.BackColor = Color.LightGoldenrodYellow; cell.Text = "enabled3"; cell.Enabled = true; cell = grid[6,2]; cell.BackColor = Color.LightGoldenrodYellow; cell.Text = "enabled4"; cell.Enabled = true; cell = grid[7,2]; cell.BackColor = Color.LightGoldenrodYellow; cell.Text = "enabled5"; cell.Enabled = true; cell = grid[8,3]; grid.CoveredRanges.Add(GridRangeInfo.Cells(8,3,8,8)); cell.BackColor = Color.LightGoldenrodYellow; cell.Text = "enabled6"; cell.Enabled = true; this.gridControl1.MoveCurrentCellDirection += new GridMoveCurrentCellDirectionEventHandler(gridControl1_MoveCurrentCellDirection); } private void gridControl1_MoveCurrentCellDirection(object sender, GridMoveCurrentCellDirectionEventArgs e) { GridControlBase grid = sender as GridControlBase; GridModel gridModel = grid.Model; int row = e.RowIndex; int col = e.ColIndex; switch (e.Direction) { case GridDirectionType.Right: { col++; if (col > gridModel.ColCount) { row++; col = grid.LeftColIndex; } while (row < gridModel.RowCount) { using (GridStyleInfo style = grid.GetViewStyleInfo(row, col)) { if (style.Enabled) { e.Result = grid.CurrentCell.MoveTo(row, col); e.Handled = true; return; } col++; if (col > gridModel.ColCount) { row++; col = grid.LeftColIndex; } } } e.Result = false; e.Handled = true; break; } case GridDirectionType.Left: { col--; if (col == gridModel.Cols.HeaderCount) { row--; col = gridModel.ColCount; } while (row > gridModel.Rows.HeaderCount) { using (GridStyleInfo style = grid.GetViewStyleInfo(row, col)) { if (style.Enabled) { e.Result = grid.CurrentCell.MoveTo(row, col); e.Handled = true; return; } col--; if (col == gridModel.Cols.HeaderCount) { row--; col = gridModel.ColCount; } } } // this will goback to toolbar e.Result = false; e.Handled = true; break; } } } we need help asap on how to deal with this behavior. regards, TA

3 Replies

AD Administrator Syncfusion Team June 17, 2005 11:25 PM UTC

This is listed in our known defects database. http://www.syncfusion.com/support/issues/grid/Default.aspx?ToDo=view&questId=283 You can tweak the work around given there to avoid the problem in your sample. It does require that you know the first and last enabled cell somehow.
private int lastEnabledRow = 8;
private int lastEnabledCol = 3;
private int firstEnabledRow = 2;
private int firstEnabledCol = 1;

private void gridControl1_CurrentCellControlKeyMessage(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellControlKeyMessageEventArgs e)
{
	GridControl grid = (GridControl) sender;
	GridCurrentCell cc = grid.CurrentCell;
	Keys keyCode = (Keys)((int)e.Msg.WParam) & Keys.KeyCode;
	if(keyCode == Keys.Tab)
	{
		if( (cc.RowIndex == lastEnabledRow && cc.ColIndex == lastEnabledCol
			&& 0 == (Control.ModifierKeys & Keys.Shift))
			|| 
			(cc.RowIndex == firstEnabledRow && cc.ColIndex == firstEnabledCol 
			&& 0 != (Control.ModifierKeys & Keys.Shift))
			)
		{
			grid.CurrentCell.EndEdit();
			grid.CurrentCell.BeginEdit();
			e.Handled = true;
			e.Result = true;
		} 
	}
}



TA Tim Aquino June 20, 2005 09:06 PM UTC

Hi, The workaround FAILS if there''s a validation on the enabled cells (_currentcellvalidating event). On the example, I''ve added a simple validation on the 1st enabled cell (2,1), to check if the value entered = ''enabled1''. If the value is not ''enabled1'', the grid/cell must revert back to the old value and cancel edit. However, the grid takes the TAB as an entry overwriting the cell value. code: ----- private void gridControl1_CurrentCellValidating(object sender, CancelEventArgs e) { // sender = the grid GridControl grid = gridControl1; // get the current cell GridCurrentCell cc = grid.CurrentCell; GridStyleInfo cell = grid[cc.RowIndex,cc.ColIndex]; // SAMPLE: 1st enabled cell if(cc.RowIndex == 2 && cc.ColIndex == 1) { if(cc.Renderer.ControlValue.ToString() == "enabled1") { // validation ok } else { // revert to old value cc.Renderer.ControlValue = cell.CellValue; e.Cancel = true; return; } } } We need help asap, or we are forced to go back to v2.1.0.9 thanks, TA


AD Administrator Syncfusion Team June 20, 2005 10:48 PM UTC

This code handled the sample problem.
if(cc.RowIndex == 2 && cc.ColIndex == 1) 
{
	if(cc.Renderer.ControlValue.ToString() == "enabled1")
	{
		// validation ok
	}
	else
	{
		// revert to old value
		cc.Renderer.ControlValue = cell.CellValue; 
		cc.CancelEdit();
		cc.BeginEdit();
		e.Cancel = true;
		return;
	}
}

            

Loader.
Up arrow icon