HighTechTalks DotNet Forums  

Why textboxes don't go blank when I click addnew

Dotnet Framework (WinForms DataBinding) microsoft.public.dotnet.framework.windowsforms.databinding


Discuss Why textboxes don't go blank when I click addnew in the Dotnet Framework (WinForms DataBinding) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Dennis
 
Posts: n/a

Default Why textboxes don't go blank when I click addnew - 09-20-2004 , 03:49 AM






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


Reply With Quote
  #2  
Old   
AT
 
Posts: n/a

Default RE: Why textboxes don't go blank when I click addnew - 09-21-2004 , 02:21 AM






Hi dennis,

Based on my understanding, you bind a dataset both to a DataGrid and
TextBoxes. You want to synchronize the DataGrid's content with TextBox.

First, can you show me more detailed information about what is "position
label" that displays "m of n"? I have no knowledage about this label.

Second, is your textboxes' databinding set through designer or manual set
in code at runtime? To synchronize DataGrid with TextBox databinding, we
should set the same datasource for these controls. Like this:

this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.dataSet11, "jobs.job_id"));
//and
this.dataGrid1.DataMember = "jobs";
this.dataGrid1.DataSource = this.dataSet11;

Then Winform will auto synchronize the databinding. If I misunderstand you,
please feel free to tell me.

================================================== ============
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Reply With Quote
  #3  
Old   
Dennis
 
Posts: n/a

Default RE: Why textboxes don't go blank when I click addnew - 09-21-2004 , 05:35 AM



Thanks Jeff,

Kevin Yu answered the question in adonet newsgroup. Here was his reply.

dennis

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


""Jeffrey Tan[MSFT]"" wrote:

Quote:
Hi dennis,

Based on my understanding, you bind a dataset both to a DataGrid and
TextBoxes. You want to synchronize the DataGrid's content with TextBox.

First, can you show me more detailed information about what is "position
label" that displays "m of n"? I have no knowledage about this label.

Second, is your textboxes' databinding set through designer or manual set
in code at runtime? To synchronize DataGrid with TextBox databinding, we
should set the same datasource for these controls. Like this:

this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.dataSet11, "jobs.job_id"));
//and
this.dataGrid1.DataMember = "jobs";
this.dataGrid1.DataSource = this.dataSet11;

Then Winform will auto synchronize the databinding. If I misunderstand you,
please feel free to tell me.

================================================== ============
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.



Reply With Quote
  #4  
Old   
AT
 
Posts: n/a

Default RE: Why textboxes don't go blank when I click addnew - 09-22-2004 , 04:14 AM



Hi Dennis,

Thansk for your feedback.

Yes, I have talked with my colleague Kevin Yu, this issue is caused by
CheckBox's null value. It seems he got much information on this issue than
me :-) Anyway, I am glad your problem is resolved, if you need further
help, please feel free to tell me. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.