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.

Cell value lost when losing focus...

Thread ID:

Created:

Updated:

Platform:

Replies:

816 Aug 20,2002 11:08 PM Aug 26,2002 05:12 AM Windows Forms 6
loading
Tags: GridControl
Sheldon Barr
Asked On August 20, 2002 11:08 PM

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.

Clay Burch [Syncfusion]
Replied On August 21, 2002 02:16 AM

> 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(); }

Clay Burch [Syncfusion]
Replied On August 21, 2002 02:42 AM

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.

Sheldon Barr
Replied On August 21, 2002 10:16 PM

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)?

Clay Burch [Syncfusion]
Replied On August 22, 2002 03:30 AM

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

Sheldon Barr
Replied On August 25, 2002 09:26 PM

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.

Clay Burch [Syncfusion]
Replied On August 26, 2002 05:12 AM

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;
	}
}

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.

;