Why textboxes don't go blank when I click addnew

G

Guest

Why textboxes don't go blank when I click addnew.

I have a FullWord form displaying KeywordSets in textboxes and a checkbox, a
grid in synch with the textboxes, and two child grids tied by relationships
to KeywordSets. One is Keywords and the other is SearchPhrase.

I have several problems with this form, but here I'll ask for help on just
one. I have 15 or so forms similar to this and when I click the add button it
works in all forms except this one. It may or may not have something to do
with the child grids. I doubt it, because edit works fine.

down to details

Everything is set up as usual in the form_load event:

Private Sub frmFullWord_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
cnWKS.ConnectionString = gstrconn
cm = CType(BindingContext(dsWKS1, "KeyWordSets"), CurrencyManager)
AddHandler cm.ItemChanged, AddressOf cm_ItemChanged
AddHandler cm.PositionChanged, AddressOf cm_PositionChanged
AddHandler daWKS.RowUpdated, AddressOf OnRowUpDated
cmK = CType(BindingContext(dsWKS1,
"KeywordSets.KeywordSetsKeywords"), CurrencyManager)
cmSP = CType(BindingContext(dsWKS1,
"KeywordSets.KeywordSetsSearchPhrase"), CurrencyManager)

daWKS.Fill(dsWKS1, "KeywordSets")
daWK.Fill(dsWKS1, "Keywords")
daWSP.Fill(dsWKS1, "SearchPhrase")
Catch ex As OleDbException
If ex.Errors(0).SQLState = "3022" Then
MsgBox(ex.Errors(0).Message & s & "Please try again")
dsWKS1.Clear()
daWKS.Fill(dsWKS1, "KeywordSets")
daWK.Fill(dsWKS1, "Keywords")
daWSP.Fill(dsWKS1, "SearchPhrase")
Exit Try
Else
Dim errorMessages As String
errorMessages += "Message: " & ex.Errors(0).Message &
ControlChars.CrLf _
& "NativeError: " & ex.Errors(0).NativeError &
ControlChars.CrLf _
& "Source: " & ex.Errors(0).Source &
ControlChars.CrLf _
& "SQLState: " & ex.Errors(0).SQLState &
ControlChars.CrLf _
& "The form will be closed"
MsgBox(errorMessages)
Me.Close()
End If
Catch ex As DBConcurrencyException
MsgBox(ex.Message & s & "The dataset will be refreshed." & s &
"Then you can navigate to the row and update it again.")
dsWKS1.Clear()
daWKS.Fill(dsWKS1, "KeywordSets")
daWK.Fill(dsWKS1, "Keywords")
daWSP.Fill(dsWKS1, "SearchPhrase")
Exit Try
Catch ex As Exception
MsgBox(ex.GetType.ToString & s & ex.Message & s & ex.HelpLink &
s & ex.StackTrace & s & ex.Source & s & "The form will be closed") '& s &
ex.TargetSite)
Me.Close()
End Try

SetEditMode(False)

End Sub

Everything is filled and I can navigate backwards and forwards. I can
edit and delete KeywordSets. No error messages.

The add button procedure is as follows:

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
cm.AddNew()
SetEditMode(True)
End Sub

pretty run on the mill. Exactly the same as with the other forms that
all work.

The position starts at 1 of 3. If I press add it stays on 1 and says 1 of
4. In the associated grid (I also show a read only grid for keyword sets.
Synch is perfect as with the other forms) The 4th row shows at the bottom
with a keywordsetid, a checked active, and null for keywordset (name) and
description.

If I move the pointer in the grid to the 4th row, the position label still
says row 1 of 4 and the contents of the textboxes are the contents of the
first row.

If I click update (end edit) no error occurs. If I try to update the
dataadapter I get the message 'No changes to submit!'. The fourth row stays
in the grid and the position label says 1 of 4.

If I close and reopen there are only 3 rows, as expected. If I try to add
from say row 2 the exact same thing happens.


I take the schema from chapter 13 of ado.net core reference, which turns
out to have several severe errors in it that were corrected mostly by people
in the forums

Can anybody help?

dennis
 
K

Kevin Yu [MSFT]

Hi Dennis,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you have called AddNew on the
currencymanager object, the textboxes were not cleared and new rows cannot
be moved to. If there is any misunderstanding, please feel free to let me
know.

I have worked on the source code you sent me last time. Based on my
research, this is a known issue of data binding. The problem lies in the
Active checkbox on the form. When there is a checkbox binding to a boolean
column, and AddNew is called, the checkbox uses the default value of that
boolean column as its value. The Checked property of a CheckBox control can
only accept boolean values (True or False) and does not understand Null.
Therefore, you cannot position CurrencyManager on a new row when the
DefaultValue of the DataColumn is set to System.DBNull.

To resolve this problem, programmatically modify the DataColumn object in
the DataTable, and then set its DefaultValue property to True or to False.
This can either be done in DataSet schema default property or add a line at
the beginning of Form_Load.

Me.dsWKS1.KeywordSets.ActiveColumn.DefaultValue = True

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

reply

thanks Kevin,

There is a default value for active, checked, true. Sometime back when I
learned I had to put in the line anyway. Somehow I forgot it in this form.
Everything worked fine. Thanks as usual. Dennis

Now on to the next problem in this form. (In another topic)
 
K

Kevin Yu [MSFT]

Hi Dennis,

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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

Top