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.

Handling cell text change

Thread ID:

Created:

Updated:

Platform:

Replies:

94891 Jun 8,2010 11:32 AM Jun 9,2010 05:04 AM Windows Forms 2
loading
Tags: Grouping
Jim Tench
Asked On June 8, 2010 11:32 AM

I have a gridGroupingControl bound to a list of objects. When a user edits or adds a new record, I want to be able to review the contents of a specific cell as the tab away (press enter, mouse click, whatever) from the cell and change the contents of the cell. I want this to happen before the record is updated/added in the underlaying data.

I'm sure there outght to be an event that allows me to do that and I thought it ought to be the validate one, but that doesn't seem to let me access the cell.value.

Help please, a pointer or 2!

Thanks

Jim

Jim Tench
Replied On June 8, 2010 12:02 PM

RecordvalueChanging Event says - Occurs when a RecordFieldCell's value is changed and before Record.SetValue is Called, No it isn't! I've implemented that like the following -
private void OnRecordValueChanging(object sender, RecordValueChangingEventArgs e)
{
if (e.FieldDescriptor.Name == "B")
{
Element el = gridGroupingControl1.Table.GetInnerMostCurrentElement();
GridTable table = el.ParentTable as GridTable;
GridTableControl tableControl = gridGroupingControl1.GetTableControl(table.TableDescriptor.Name);
GridCurrentCell cc = tableControl.CurrentCell;
cc.Renderer.ControlValue = "Albert";
}
}

Setting a breakpoint on cc.renderer.ControlValue = "Albert" and stepping past it, I can clearly see the ControlValue contains Albert, but hitting F5 and looking at the result in the grid, the data hasn't changed!

That makes no sense what so ever!

Jisha Joy [Syncfusion]
Replied On June 9, 2010 05:04 AM

Hi Jim,

We need to handle TableControlCurrentCellValidating event to done validation on the grid cell before the values are getting committed. The Validating event is the best to handle when you want to validate the contents you entered. You can set e.Cancel to true in this event to indicate validation failed. See the code:


void gridGroupingControl1_TableControlCurrentCellValidating(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCancelEventArgs e)
{
GridTableCellStyleInfo style = e.TableControl.CurrentCell.Renderer.CurrentStyle as GridTableCellStyleInfo;
if (style.TableCellIdentity.Column != null && style.TableCellIdentity.Column.Name == "Item")
{
if (e.TableControl.Table.CurrentRecord.Kind != DisplayElementKind.AddNewRecord)// Check for AddNewRecord
{
e.TableControl.Table.CurrentRecord.EndEdit();
}
else
{
GridCurrentCell cc = e.TableControl.CurrentCell;

if (cc.Renderer.ControlText == "wrong") // check for the desired value

{
MessageBox.Show("Not a valid value");
e.Inner.Cancel = true;

}

}
}

}




Sample for your reference:

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GCCValidations1376151774.zip

Please let me know if this helps.

Regards,
Jisha

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.

;