?
Solved

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

Posted on 2012-04-10
4
Medium Priority
?
1,220 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 2000 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

How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

762 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