Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now