Solved

Visual Studio VB.NET WinForm Default Value in textbox field on Form

Posted on 2012-04-10
4
1,200 Views
Last Modified: 2012-04-12
I am trying to auto fill a few Text boxes on a WinForm.  The code I have is putting the correct value in the text boxes, but they are not passing through to the database.  If I manually put a value in those same fields, deleting the auto fill value, the new value is saved to the database field.

Is there something wrong in my code, or is the textchanged event the wrong place to put the auto fill?  Maybe a page_load?  if so how would i do it.  

Completely changing my code for auto fill would be fine too.  

Thanks.  

 Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.Controls.Add(PrintButton)

        'default for cab card No.
        ConAgraTruckCoTextBox.Tag = "164"
        ConAgraTruckCoTextBox.Text = CStr(ConAgraTruckCoTextBox.Tag)

        'default for SemiLbTare
        SemiLbTareTextBox.Tag = "0"
        SemiLbTareTextBox.Text = CStr(SemiLbTareTextBox.Tag)

        'default for PullLbTare
        PullLbTareTextBox.Tag = "0"
        PullLbTareTextBox.Text = CStr(PullLbTareTextBox.Tag)



  'second part of ConagraTextbox
    Private Sub ConAgraTruckCoTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConAgraTruckCoTextBox.TextChanged
        If String.IsNullOrEmpty(ConAgraTruckCoTextBox.Text) Then
            ConAgraTruckCoTextBox.Text = CStr(ConAgraTruckCoTextBox.Tag)
            ConAgraTruckCoTextBox.SelectAll()
        End If
    End Sub

    'default SemiLbTare

    Private Sub SemiLbTareTextBox_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SemiLbTareTextBox.TextChanged
        If String.IsNullOrEmpty(SemiLbTareTextBox.Text) Then
            SemiLbTareTextBox.Text = CStr(SemiLbTareTextBox.Tag)
            SemiLbTareTextBox.SelectAll()
        End If
    End Sub

    'default PullLbTare

    Private Sub PullLbTareTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PullLbTareTextBox.TextChanged
        If String.IsNullOrEmpty(PullLbTareTextBox.Text) Then
            PullLbTareTextBox.Text = CStr(PullLbTareTextBox.Tag)
            PullLbTareTextBox.SelectAll()
        End If
    End Sub

    'default SemiCert

    Private Sub SemiCertTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SemiCertTextBox.TextChanged
        If String.IsNullOrEmpty(SemiCertTextBox.Text) Then
            SemiCertTextBox.Text = CStr(SemiCertTextBox.Tag)
            SemiCertTextBox.SelectAll()
        End If
    End Sub
0
Comment
Question by:rtay
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37830118
Remove all textchanged events and validate your textboxes on submit button.
0
 
LVL 5

Author Comment

by:rtay
ID: 37830389
This worked if I tabbed through the textbox in the form.  Any ideas to put the values in without a tab through?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37835387
Are these textboxes bound? Try calling the WriteValue on the binding after you update the textbox programmatically

SemiCertTextBox.DataBindings(0).WriteValue()

http://msdn.microsoft.com/en-us/library/system.windows.forms.binding.writevalue.aspx
0
 
LVL 5

Author Closing Comment

by:rtay
ID: 37838909
thank you.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question