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

Tying fields'' values in ggc

Hi everybody,

What is the ggc event that's raised before/after a new record is inserted programatically / via editing the grid ?


Thanks in advance.

6 Replies

RH Ryan Hardoon March 26, 2007 09:39 AM UTC

Is there a way to set a field's value automatically, according to other fields' values ?


RA Rajagopal Syncfusion Team March 26, 2007 06:03 PM UTC

Hi Ryan,

The SourceListListChanged event of the GridGroupingControl will get triggered when you insert a new record programatically. This will fire before and after the new record is inserted while editing.

private void gridGroupingControl1_SourceListListChanged(object sender, TableListChangedEventArgs e)
{
if(e.ListChangedType == ListChangedType.ItemAdded)
{
Console.WriteLine("Record Inserted");
}
}

You can retrieve the value from the field that you want to set to other using the record.GetValue() method. Then, use the record.SetValue() to programatically set the value to other field.

object val = record.GetValue( fieldname1 ); // retrieve the value
record.SetValue( fieldName2, val ); // set the value

Let us know if you have any other questions.
Regards,
Rajagopal


RH Ryan Hardoon March 27, 2007 08:22 AM UTC

Thanks, it worked fine.

For some reason, I couldn't see SetValue while editing. I used TableControlCurrentCellAcceptedChanges, which was more appropriate to our needs.

Anyway, I have another small problem in which I'd be happy if you could point me to the right direction.
I have a button thet sets one of my MaskEdit fields (not sore being a MaskEdit has any relevancy). It seems to do the job well when the current record represents a valid row in the data source, but it has no effect when I'm editing an AddNewRecord row. My guess is that either "ggc.Table.CurrentRecord" is not the object to address in this case, or it is loked via some flag.

Please see if you could help me out.


Thanks.


JS Jeba S Syncfusion Team March 27, 2007 08:38 AM UTC

Hi Ryan,

You can try handling CurrentRecordContextChange and set the defaults there if you are starting to edit a record.

private void gridGroupingControl1_CurrentRecordContextChange(object sender, Syncfusion.Grouping.CurrentRecordContextChangeEventArgs e)
{
if(e.Action == CurrentRecordAction.BeginEditComplete && e.Record is GridAddNewRecord)
{
GridAddNewRecord rec = e.Record as GridAddNewRecord;
rec.SetValue("Col0", "Col0Default");
rec.SetValue("Col1", "Col1Default");
rec.SetValue("Col2", "Col2Default");
rec.SetValue("Col3", "Col3Default");
}
}


Kindly let us know if this helps.

Best Regards,
Jeba.


RH Ryan Hardoon March 28, 2007 03:39 AM UTC

Thanks Jeba, this could indeed com in handy to us very soon.
However, the button is not a workaround, but a desired component in out application.
I need access to the AddNew record while editing a field, outside of ggc events.
The only way I could do this using CurrentRecordContextChange is by setting e.Record to a global member, and I'd prefer accessing this record directly via the ggc.


JS Jeba S Syncfusion Team March 28, 2007 08:20 AM UTC

Hi Ryan,

Try these code snippet to set the newvalue to the AddNewRecord of the GridTable.

GridTable table = this.gridGroupingControl1.GetTable("YourTableName");
table.BeginEdit();

Record r = null;
foreach(Element el in table.DisplayElements)
{
if( el.Kind == DisplayElementKind.AddNewRecord )
{
r = el.ParentRecord;
r.SetCurrent();
if( r != null)
{
if (r.IsCurrent)
{
r.BeginEdit();
if (r.IsEditing)
{
r.SetValue("YourColumnName", "BX");
r.SetValue("YourColName", "ID");
//If you want to add the record to the table call EndEdit...
//r.EndEdit();
}
}
}
break;
}
}
//If you want to add the record to the table call EndEdit...
//table.EndEdit();


Kindly let us know if this helps.

Best Regards,
Jeba.

Loader.
Live Chat Icon For mobile
Up arrow icon