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.
Syncfusion Feedback

Tying fields'' values in ggc

Thread ID:

Created:

Updated:

Platform:

Replies:

58649 Mar 26,2007 09:16 AM UTC Mar 28,2007 08:20 AM UTC Windows Forms 6
loading
Tags: GridControl
Ryan Hardoon
Asked On March 26, 2007 09:16 AM UTC

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.

Ryan Hardoon
Replied On March 26, 2007 09:39 AM UTC

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

Rajagopal [Syncfusion]
Replied On 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

Ryan Hardoon
Replied On 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.

Jeba S [Syncfusion]
Replied On 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.

Ryan Hardoon
Replied On 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.

Jeba S [Syncfusion]
Replied On 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.

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.

Warning Icon 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.Close Icon

;