[SOLVED] Issue with BindingSource AddingNew Event

Answered
0
0

Hi,

I have a datagridview tied to a bindingsource and when I go to the new row on the grid I fire the AddingNew event on the bindingsource.  This usually fires right when the user enters the row but it is not firing until the user enters a value in one of the cells and even then the defaults are not showing on the grid.

Your advice is appreciated and this is a pretty big deal for our applications.

Thanks, Tim

  • You must to post comments
Best Answer
0
0

Hi Tim,

For the event firing issue,  the row is only created after the first value is entered, this is by design, different from WinForms.  We do this so the row is not recreated every time the user clicks on it and removed every time they click out of it.  If you attach a solution demonstrating the behavior you’re trying to replicate with the event I can help find a workaround for it!

For the default value, it’s a known issue and I’m attaching a sample that you can use as a template and modify to get your desired behavior as a workaround.  It’s a known bug and we’re working on the solution.

Let me know if this works for you!

Best regards,

Levie

  • You must to post comments
0
0

Hi Ewan,

not sure if it helps in your case but in a similiar situation adding the following code to a customers project did fix that issue:

Attach to the ColumnChanging event of your DGV and add the following code in the event handler:

if (e.ProposedValue == null)
	{
		e.ProposedValue = DBNull.Value;
	}

 

If that does not help, please send us more information/code that helps us to understand & reproduce that issue.

Best regards
Frank

  • Ewan Walker
    Hi Frank works, the event is attached to the underlying datatable
  • Frank (ITG)
    Hi Ewan, yes, sorry please attach it to the DataTable, not the DGV. I was writing my answer beetween 2 meetings and it was not precise enough. Glad you figured it out. Best regards, Frank
  • Ewan Walker
    Hi Frank I get it now. Default Values Needed fires when the DGV is populated and whenever a new row is created so that there is always a blank row pre-set with default values, that does not exist in the underlying data table, Whereas Column Changing fires when the row is actually being created to set default values.
  • You must to post comments
0
0

I have a data bound DGV with and index column which cannot be null.

When I try

private void dgvTest_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
if (!isLoading && !isSaving)
{
//dgvTest[5, e.RowIndex].Value = 0;
e.Row[5].Value = 0;
}
}

Which fires after you add the first value to the row, effect of setting the default value is to create a second new row with the first row producing a null value error.

How do I get round this?

Attachment
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.