Connecting Tech Pros Worldwide Help | Site Map

Populated results from combobox to textbox ?

Newbie
 
Join Date: Jan 2009
Location: NE. Ohio
Posts: 2
#1: Jan 9 '09
I'll start this hopefully simple and add code where needed or requested.

Im using a combobox that bound to a DataSet. The Dataset retreives it's values from SQL.

I can retreive the values fine. However only displaying (1) Column. Which is fine.

Here's where it gets complicated for me. The dataset has 2 other columns that get filled. I need the resulting columns to be sent to text boxes when I select a value from the combobox.

Basically:
Expand|Select|Wrap|Line Numbers
  1.  txtbox1.text = combobox.column(2).selectedvalue
  2.  txtbox2.text = combobox.column(3).selectedvalue
However. using the method of course doesnt work and that's what I need to figure out.
Newbie
 
Join Date: Jan 2009
Location: NE. Ohio
Posts: 2
#2: Jan 9 '09

re: Populated results from combobox to textbox ?


OK. For anyone looking for this in the future let me tell you how I went about this.

I filled the DataSet with Data From SQL. Bound a ComboBox to the DataSet.
Expand|Select|Wrap|Line Numbers
  1.  txtbox1.text = dataset.tables("table name here").Rows(cbox1.selectedindex).Item("Column name here")
  2.  
  3.  txtbox2.text = dataset.tables("table name here").Rows(cbox1.selectedindex).Item("Column name here")
  4.  

First issue I ran into was VB sending errors because the first column was yet to be populated so I had to set the index of cbox1 to 0
Expand|Select|Wrap|Line Numbers
  1.  cbox1.selectedindex = 0
Then for the selected index chage event
Expand|Select|Wrap|Line Numbers
  1. If cbox1.selectedindex = -1 then
  2.   cbox1.selectedindex = 0
  3. end if
  4.  
  5. txtbox1.text = dataset.tables("table name here").Rows(cbox1.selectedindex).Item("Column name here")
  6.  
  7. txtbox2.text = dataset.tables("table name here").Rows(cbox1.selectedindex).Item("Column name here")
  8.  
Thats all there was too it. being a novice I was actually trying to get the data from the Column instead of the Row. "STUPID. Yes.."

If anyone wants to modify and tell of any other way we can make this better I would appreciate it.
Newbie
 
Join Date: Jan 2009
Posts: 7
#3: Jan 21 '09

re: Populated results from combobox to textbox ?


Seems like you were able to solve your problem well.. I tend to favor using the "With" statement when I have long object strings since each '.' is basically telling an object traversal.. I would just change the following like so:

Expand|Select|Wrap|Line Numbers
  1. With dataset.tables("table name here").Rows(cbox1.selectedindex)
  2.    txtbox1.text = .Item("Column name here")
  3.    txtbox2.text = .Item("Column name here")
  4. End With
Reply

Tags
bind, combobox, databind, dataset, textbox


Similar Visual Basic .NET bytes