Populated results from combobox to textbox ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dibblm
    New Member
    • Jan 2009
    • 2

    Populated results from combobox to textbox ?

    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:
    Code:
     txtbox1.text = combobox.column(2).selectedvalue
     txtbox2.text = combobox.column(3).selectedvalue
    However. using the method of course doesnt work and that's what I need to figure out.
    Last edited by Frinavale; Jan 21 '09, 02:50 PM. Reason: added [code] tags
  • dibblm
    New Member
    • Jan 2009
    • 2

    #2
    Figured it out myself after days of searching. Here's what I did.

    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.
    Code:
     txtbox1.text = dataset.tables("table name here").Rows(cbox1.selectedindex).Item("Column name here")
    
     txtbox2.text = dataset.tables("table name here").Rows(cbox1.selectedindex).Item("Column name here")

    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
    Code:
     cbox1.selectedindex = 0
    Then for the selected index chage event
    Code:
    If cbox1.selectedindex = -1 then
      cbox1.selectedindex = 0
    end if
    
    txtbox1.text = dataset.tables("table name here").Rows(cbox1.selectedindex).Item("Column name here")
    
    txtbox2.text = dataset.tables("table name here").Rows(cbox1.selectedindex).Item("Column name here")
    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.
    Last edited by Frinavale; Jan 21 '09, 02:51 PM. Reason: added [code] tags

    Comment

    • Xennex
      New Member
      • Jan 2009
      • 7

      #3
      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:

      Code:
      With dataset.tables("table name here").Rows(cbox1.selectedindex)
         txtbox1.text = .Item("Column name here")
         txtbox2.text = .Item("Column name here")
      End With
      Last edited by Xennex; Jan 21 '09, 08:34 AM. Reason: code was incorrect

      Comment

      Working...