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
close icon

Cell value lost when losing focus...

Question 1. When editing the value in a cell, the new value is lost if the focus is transferred to another control on the form (one that is not part of the grid). Is there a way to get the cell to retain the new value? Question 2. I have a custom control that I want to use to edit values in a certain column of cells in a data bound grid. Is there any documentation/sample code available that covers how to write a custom cell renderer that includes a custom control (or just something like a TextBox)? Is it possible to release the source code for some of the base classes (eg. GridTextBoxCellRenderer) with the evaluation download so it's possible to properly understand the usefulness of the product? Thanks in advance for any help you can provide.

6 Replies

CB Clay Burch Syncfusion Team August 21, 2002 06:16 AM UTC

> Question 1. > > When editing the value in a cell, the new value is lost if the focus is transferred to another control on the form (one that is not part of the grid). > > Is there a way to get the cell to retain the new value? > > Question 2. > > I have a custom control that I want to use to edit values in a certain column of cells in a data bound grid. Is there any documentation/sample code available that covers how to write a custom cell renderer that includes a custom control (or just something like a TextBox)? > > Is it possible to release the source code for some of the base classes (eg. GridTextBoxCellRenderer) with the evaluation download so it's possible to properly understand the usefulness of the product? > > Thanks in advance for any help you can provide. Regarding 1, you can force the changes to be committed as the grid loses focus by handling the CurrentCellDeactivating event, and calling EndEdit on the currentcell if it is being edited. private void gridControl1_CurrentCellDeactivating(object sender, System.ComponentModel.CancelEventArgs e) { if(this.gridControl1.CurrentCell.IsEditing) this.gridControl1.CurrentCell.EndEdit(); }


CB Clay Burch Syncfusion Team August 21, 2002 06:42 AM UTC

Regarding 2: There are 8 cellrenderer sample classes among the sample projects that ship with the current evaluation. You can do a search on 'cellrenderer' in the Samples folder to spot the exact samples. All but two of these derive from the Static cell renderer class, and the other two derive from GridDropDownCellRenderer. There is also the derived cell control section (3.15) in the User's Guide that might be helpful. As far as getting source code during an evaluation, our sales teams will be glad to discuss any special needs you have regarding your evaluation. You can email to sales@syncfusion.com or call 1-888-9DOTNET or 1-919-460-6404 for more information.


SB Sheldon Barr August 22, 2002 02:16 AM UTC

Clay, thanks for the quick response, I added the CurrentCellDeactivating handler you suggested and it works fine. One more question, how would I go about getting the contents of a cell to become selected when the cell gets focus (like happens with TextBox controls)?


CB Clay Burch Syncfusion Team August 22, 2002 07:30 AM UTC

In version 1.0.2.4, there is a property that will take care of this. Try setting GridControl.ActivateCurrectCellBehavior to SlectAll.


SB Sheldon Barr August 26, 2002 01:26 AM UTC

Ok, got that working. Just one more, how do I setup the grid so that the Tab key will move from the last column of a row to the first column of the next row. Thanks again.


CB Clay Burch Syncfusion Team August 26, 2002 09:12 AM UTC

Currently, there is no property that controls this, but you can implement through a derived grid and a couple of overrides. Below is a sample.
public class MyGridControl : GridControl
{
	//needed to handle all tabs except active border edit cell
	protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
	{
		if((e.KeyData & Keys.KeyCode) == Keys.Tab && MoveToNextCell())
			return;
		
		base.OnKeyDown(e);
	}

	//this is needed to handle tab key on active cell at a border...
	protected override bool ProcessKeyPreview(ref System.Windows.Forms.Message m)
	{
		if((Keys)((int)m.WParam) == Keys.Tab)
		{
			if(MoveToNextCell())
				return true;
		}
		return base.ProcessKeyPreview(ref m);
	}

	private bool MoveToNextCell()
	{
		bool b = false;
		GridDirectionType direction = ((Control.ModifierKeys & Keys.Shift) == 0) ? GridDirectionType.Right: GridDirectionType.Left ;
		int row = this.CurrentCell.RowIndex;
		int col = this.CurrentCell.ColIndex;
		if(direction == GridDirectionType.Right)
			col++;
		else
			col--;
		if(!this.CurrentCell.QueryNextEnabledCell(direction, ref row, ref col))
		{
			if(direction == GridDirectionType.Right && this.ColCount == this.CurrentCell.ColIndex
				&& this.RowCount > this.CurrentCell.RowIndex)
			{
				row = this.CurrentCell.RowIndex + 1;
				col = 1;
				if(this.CurrentCell.QueryNextEnabledCell(direction, ref row, ref col))
				{
			this.CurrentCell.MoveTo(row, col, 
						GridSetCurrentCellOptions.ScrollInView);
					b = true;
				}
			}
			else if(direction == GridDirectionType.Left && 1 == this.CurrentCell.ColIndex
				&& this.CurrentCell.RowIndex > 1)
			{
				row = this.CurrentCell.RowIndex - 1;
				col = this.ColCount;
				if(this.CurrentCell.QueryNextEnabledCell(direction, ref row, ref col))
				{
					this.CurrentCell.MoveTo(row, col, 
							GridSetCurrentCellOptions.ScrollInView);
					b = true;
				}
			}
		}
		return b;
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon