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

Accessing the new DataRow in GDBG

Hi, I need to access to the new DataRow when adding a new row to the grid. This have to be before the Binder.EndEdit() method is called(e.g. leaving the added row in the grid). Regards Thomas

5 Replies

AD Administrator Syncfusion Team February 6, 2003 07:44 PM UTC

You might try the EditModeChanged event of GridModelDataBinder. This is called for every row when the user starts editing the row but you can check if the edited record is the last record; this.gridDataBoundGrid1.Binder.EditModeChanged += new EventHandler(BinderEditModeChanged); void BinderEditModeChanged(object sender, EventArgs e) { CurrencyManager cm = sender as CurrencyManager; if (this.gridDataBoundGrid1.Binder.IsEditing && this.gridDataBoundGrid1.Binder.RecordCount-1 == this.gridDataBoundGrid1.Binder.CurrentPosition) System.Diagnostics.Trace.WriteLine("Add New" + this.gridDataBoundGrid1.Binder.RecordCount.ToString()); } Stefan


TZ Thomas Zueger February 7, 2003 05:11 PM UTC

Stefan, The code you posted does not work, bacause the sender is a type of Syncfusion.Windows.Forms.Grid.GridModelDataBinder. I'm changing the code to: void BinderEditModeChanged(object sender, EventArgs e) { Syncfusion.Windows.Forms.Grid.GridModelDataBinder binder = sender as Syncfusion.Windows.Forms.Grid.GridModelDataBinder; CurrencyManager cm = (CurrencyManager)binder.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember]; if (this.gridDataBoundGrid1.Binder.IsEditing && this.gridDataBoundGrid1.Binder.RecordCount-1 == this.gridDataBoundGrid1.Binder.CurrentPosition) System.Diagnostics.Trace.WriteLine("Add New" + this.gridDataBoundGrid1.Binder.RecordCount.ToString()); } Regards Thomas


KL Ken Law March 16, 2003 04:04 PM UTC

The problem with this method is that it doesn't guarantee you have a new row because conditions are the same when you re-edit the last row (you can't set a default value again - the user may have changed it during the initial edit). I've been very frustrated trying to do something that should be extremely simple. Setting default values in new rows. Using RowEditing or RowEnter is a problem because the datasource does not yet have a record to edit. Trying to set the CellValue just doesn't work (no effect). There really should be a default value property in GridBoundColumn.StyleInfo to avoid even having to write code. Otherwise, there should be a NewRow event so default values can be set. This is the most basic of needs.


SG Sean Greer March 19, 2003 09:23 PM UTC

While the GridBoundColumn does not have a DefaultValue property, the DataColumn class does. Can you not set the default value in this way? HTH, Sean


KL Ken Law March 22, 2003 11:31 PM UTC

I can't set the default in the DataColumn because the default value depends on which of several GDBGs is editing the data. Each grid sets this default value which serves as a filter value for the DataView attached to the particular grid. The ideal solution would be a NewRow event that happens when the underlying data source adds a row. Then defaults could be reliably set based on virtually any criteria.

Loader.
Live Chat Icon For mobile
Up arrow icon