CurrencyManager.AddNew - Cancel ??

  • Thread starter Thread starter a
  • Start date Start date
A

a

Hey Gang,

I posted this on .DataBinding, but that is a dead group (no activity) so I
retracted it.

I am actively overcoming my fears and prejudices toward DataBindinding, and
have come across another issue.

My setup is like this:

3 textboxes bound to a table in the dataset (tbl1). A listbox that shows
all records in the table.
3 more textboxes bound to tbl2 in the same dataset, the child table of tbl1.

I have 2 currency managers, one for the Parent, and one for the Child
tables.

The AddNew button for the child calls cmChild.AddNew

I need to havdle the case where a user then clicks another record in the
listbox. I get an error thrown about tbl2 fields not allowing nulls. This
occurs before any events on the CurrencyManager, and After my Listbox's
Click event. How would I handle this (what event), and do I just call
'CancelCurrentEdit'?

Thanks!

Kevin
 
Hi,

From your description, the error is most likely thrown when the current
data row is ending the edit mode,

However in my test, if no EndCurrentEdit is called, the newly added line in
child table will be canelled automatically,when you move the Current
position of parent CurrencyManager. So there might be some other reasons
which caused the EndCurrentEdit method be called.

as you mentioned you got an error, is it an unhandled exception? If yes,
could you paste the stack trace to help further investigating this issue?

If it is just an error messagebox, we can get the stack trace in this way:
1. run your program in IDE with debugging.
2. click "break all" when the error messagebox is shown.
3. get the calling stack in the "Calling stack" pane.

Note, to get more information from the calling stack, please make sure you
had loaded the correct symbol files before getting the calling stack, (you
may check it in Modules pane, ).

If you have anything unclear about this issue, please feel free to reply
this issue.

Have a nice day!
Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Thanks for the reply!

To re-cap, in simple form, I have a list box bound to a dataset, along with
a few textboxes. I use the listbox for navigation, and the textboxes for
editing / data entry. I have an 'Add New' button that call AddNew on a
currency manager that is global to the form.

When I click AddNew, a new row is added to the listbox, and it is selected.
If a user then clicks an existing row (to cancel the AddNew), I get an error
about columns in the dataset that do not allow Nulls. I can't seem to find
a place to tie in to just cancel the edit.

This is the immediate error:

An unhandled exception of type 'System.Data.NoNullAllowedException' occurred
in system.data.dll
Additional information: Column 'BuildingName' does not allow nulls.

I do not have symbols for system.data. Are they available?

Kevin
 
Hi Kevin,

You may follow this KB article to get the correct symbol files for
debugging.
HOW TO: Use a Symbol Server with the Visual Studio .NET Debugger
http://support.microsoft.com/?id=319037

I did some test on my system, I will got the same exception if I bound the
listbox to a table, then call AddNew on that table and select another item.
However this issue does not occur in my test if the listbox is bound to the
parent table and the addnew was called on the child table.
Anyway, this cause will be more clear after getting the calling stack with
symbol.

A possible workaround I can think of for this problem now is overriding the
Listbox.OnSelectedIndexChanged event and put a try catch block around the
base.SelectedIndexChanged, in catch block you can call CancelCurrentEdit
and set the Position to new position.

Does this way resolve your problem?
If you still have problem on this issue, please feel free to reply this
thread.

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Back
Top