Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox Bound to ComboBox Text property when SelectedIndex = -1

Status
Not open for further replies.

WantsToLearn

Programmer
Feb 15, 2003
147
0
0
US
TextBox bound to a CombBox Text property similar to this:

TextBox1.DataBinding.Add("Text", ComboBox1, "Text")

If the ComboBox SelectedIndex is -1

1. Do I have to manually set TextBox1.Text property = ""
2. If I do that, does it impact the DataBinding in any way
 
1. depends on what you mean, do you mean you set selectedindex to -1 via code or is the field you bound empty?
2. yes, but I would recommend changing the dataset.

Don't forget the selectedvalue property when you want to set a combobox to empty.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Sorry I wasn't more precise in my first post. From my VB6 days, you could set in code the SelectedIndex to -1 so the ComboBox didn't initially display anything.

On my form I have a Button, 2 TextBoxes and a ComboBox which I filled from Northwind. The code below works
Code:
Form Load code
    ... pulled some code out to condense
    Me.ComboBox1.DataSource = mDataSet.Tables("Customers")
    mDataTable = CType(Me.ComboBox1.DataSource, DataTable)
    Me.ComboBox1.ValueMember = "CustomerID"
    Me.ComboBox1.DisplayMember = "CompanyName"
    Me.TextBox1.DataBindings.Add("Text", ComboBox1, "Text")
    Me.TextBox2.DataBindings.Add("Text", ComboBox1, "SelectedValue")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    mDataTable.DefaultView.RowFilter = "False"
    Me.TextBox2.Text = Nothing
End Sub

Private Sub ComboBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.GotFocus
    mDataTable.DefaultView.RowFilter = Nothing
End Sub
I just wondered if there was a better way. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top