clearing a text box

G

gordon

Hi,

I am using vb.net and loading up some SAS data into some text boxes based on
an id selected in a combo box. I have a button that I wish to use to clear
all the text box values and to set the combo box to a non-value "Select
one...". I cannot get the boxes to clear. Several attemps have allowed me
to clear the last box but not the others.

Any help appreciated


my code is :

Public cnsas As New OleDb.OleDbConnection

Public ds As DataSet = New DataSet

Private Sub GetData()

Dim SASLibrary As String = "C:\"

Try

cnsas.ConnectionString = _

"Provider=sas.LocalProvider.9.1;Data Source=" & SASLibrary

cnsas.Open()

Dim cmd As OleDb.OleDbCommand = cnsas.CreateCommand

cmd.CommandType = CommandType.TableDirect

cmd.CommandText = "Products"

Dim oleDA As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(cmd)



oleDA.Fill(ds, "Products")

ComboBox1.DataSource = ds.Tables("Products")

ComboBox1.DisplayMember = _

ds.Tables("Products").Columns("ProductID").ToString()

PopulateTextboxes(0)

Catch ex As Exception

MessageBox.Show( _

"Type : " & ex.GetType.ToString() & vbCr & _

"Message = " & ex.Message)

End Try

End Sub

Sub PopulateTextboxes(ByVal RowID As Integer)


Dim drow1 As DataRow = ds.Tables("Products").Rows(RowID)

TextBox1.Text = drow1("ProductName")

textbox2.Text = drow1("UnitPrice")

TextBox3.Text = drow1("QuantityperUnit")

TextBox4.Text = drow1("UnitsInStock").ToString()

End Sub

Private Sub form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

GetData()

End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

ComboBox1.Text = "Choose one..."

PopulateTextboxes(ComboBox1.SelectedIndex)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

End

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

ComboBox1.Text = "Choose one..."

TextBox4.Text = (" ").ToString()

TextBox4.Text = (" ").ToString()

TextBox4.Text = (" ").ToString()

TextBox4.Text = (" ").ToString()

End Sub

End Class
 
P

Peter van der Goes

gordon said:
Hi,

I am using vb.net and loading up some SAS data into some text boxes based
on an id selected in a combo box. I have a button that I wish to use to
clear all the text box values and to set the combo box to a non-value
"Select one...". I cannot get the boxes to clear. Several attemps have
allowed me to clear the last box but not the others.

Any help appreciated
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

ComboBox1.Text = "Choose one..."

TextBox4.Text = (" ").ToString()

TextBox4.Text = (" ").ToString()

TextBox4.Text = (" ").ToString()

TextBox4.Text = (" ").ToString()

End Sub

End Class
It appears from your code that you are only clearing TextBox4 ( four times).
See above.
And, why not just TextBox1.Text = "" ?
 
H

Herfried K. Wagner [MVP]

Brian Henry said:
dont clear with " " use string.empty to clear it

ACK. Instead of 'String.Empty' you can type '""' too, which is more
readable than 'String.Empty'. In addition to that, no 'ToString' is
required because '""' is already a string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top