AddNew of the BindingContext isn't working..... ?

  • Thread starter Thread starter Aaron Smith
  • Start date Start date
A

Aaron Smith

I have a form, oddly enough the same one with the expression column that
is giving me a headache, and on this form I have a dataset that has a
couple of tables in it that are related. If I do a AddNew on the Binding
Context for the parent, it doesn't seem to work. If I click the new
(just does an addnew, and thats it) the fields do not clear out, and if
I click new again, it just says that the first field that doesn't allow
nulls, doesn't allow nulls. I can't seem to figure it out... I don't
know if it's related, but also another problem I am having is if I
change the position property, even though none of the data has changed,
it will set the modified flag of the dataset. None of my other forms
does this, so I know it's not default behavior.... I am lost.. Any idea
where to even start to look?

Aaron
 
Aaron,

I think you need to give us some code to explain it more, now we even don't
know if you use the currencymanager.addnew or the dataview.addnet. I think
there are more things what could be in thousand ways done in your question.

Cor
 
I dont' know how much to post, but this is my New button in the toolbar:

Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As
C1.Win.C1Command.ClickEventArgs) Handles cmdNew.Click
Try
Me.BindingContext(CoursesDS1, "Courses").EndCurrentEdit()
Me.BindingContext(CoursesDS1, "Courses").AddNew()
Catch ex As Exception
Misc.ShowError(ex.Message())
End Try
End Sub

This is a pretty standard form.. Nothing fancy, MSDE. Quite a few
tables, but only two tables that get changed from here. The rest are
"lookups" ... There is a course table that has a related child called
InstClasses ...

Is this enough? What specific code do you need? All I did was drag some
data adapters on the form, run their wizards, and then created the
datasets using those wizards. Thats it.

Aaron

Cor said:
Aaron,

I think you need to give us some code to explain it more, now we even don't
know if you use the currencymanager.addnew or the dataview.addnet. I think
there are more things what could be in thousand ways done in your question.

Cor
 
Ok.. I found the location of the problem. This doesn't mean I found the
solution.. lol

I have two custom textboxes on the form that are derived from Textbox..
I just did this so that I could have the data formatted to Currency. If
this procedure is in there to add the formatting, then the AddNew does
not work.

If I take it out, everything works great. I would rather not set the
formatting in the form every time I need to use the currency mask. I
want, well lets just say I need, it inside the custom textbox class. If
it's not in the textbox, then all sorts of problems will happen when we
start having the other developers work on these projects.

Private Sub CurrencyMaskedTextBox_BindingContextChanged(ByVal
sender As Object, ByVal e As System.EventArgs) Handles
MyBase.BindingContextChanged
If Me.DataBindings.Count > 0 Then
AddHandler Me.DataBindings(0).Format, AddressOf
DecimalToCurrencyString
AddHandler Me.DataBindings(0).Parse, AddressOf
CurrencyStringToDecimal
End If
End Sub

What should I be doing instead of this to make it work right?

Aaron

Aaron said:
I dont' know how much to post, but this is my New button in the toolbar:

Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As
C1.Win.C1Command.ClickEventArgs) Handles cmdNew.Click
Try
Me.BindingContext(CoursesDS1, "Courses").EndCurrentEdit()
Me.BindingContext(CoursesDS1, "Courses").AddNew()
Catch ex As Exception
Misc.ShowError(ex.Message())
End Try
End Sub

This is a pretty standard form.. Nothing fancy, MSDE. Quite a few
tables, but only two tables that get changed from here. The rest are
"lookups" ... There is a course table that has a related child called
InstClasses ...

Is this enough? What specific code do you need? All I did was drag some
data adapters on the form, run their wizards, and then created the
datasets using those wizards. Thats it.

Aaron
 
Problem solved.... The format event was the problem. In the event
handler, it was only checking the type. It seems that if the value
itself is DBNull, it was still continuing on. No exceptions were being
thrown..

Public Shared Sub DecimalToCurrencyString(ByVal sender As Object,
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then Exit Sub ' Added this line
to fix the problem.
If Not cevent.DesiredType Is GetType(String) Then Exit Sub
cevent.Value = Strings.Format(CDec(cevent.Value), "Currency")
End Sub
 
Aaron,

I am glad that you solved it without myhelp, however often is the need to
describe something for someone else the first step to find a solution for a
problem

Cor
 
Yea, that was one that I don't think anyone could have helped me with
unless they saw all the code for the form. I didn't even know where to
look until I started to remove the bindings for all the textbox objects.
Unfortunately, out of about 30 on the form, that was the last one I removed.

Cor said:
Aaron,

I am glad that you solved it without myhelp, however often is the need to
describe something for someone else the first step to find a solution for a
problem

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top