Handling cell text change
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
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
SIGN IN To post a reply.
2 Replies
JT
Jim Tench
June 8, 2010 04:02 PM UTC
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!
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!
JJ
Jisha Joy
Syncfusion Team
June 9, 2010 09:04 AM UTC
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:
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
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
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
JT Jim Tench
- Jun 8, 2010 03:32 PM UTC
- Jun 9, 2010 09:04 AM UTC