Solved

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

Posted on 2012-04-10
4
1,207 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

749 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