Solved

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

Posted on 2012-04-10
4
1,213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

707 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