Combobox problem

ribbysmurf

Member
Joined
Jul 27, 2003
Messages
9
below is my source code.. im using datasouce to bind data to my combo box, the problem is that after bind to my combo box. i can get the text using combobox1.item(index)... can somebody pls help me?
Code:
        path = Application.StartupPath + "\data.mdb"
         Creating connection and command sting
        sqlStr = "SELECT * FROM problem"
         Create connection object
        Dim connp As OleDbConnection = New OleDbConnection(conStr)
         Create data adapter object
        Dim dap As OleDbDataAdapter = New OleDbDataAdapter(sqlStr, conn)

         Create a dataset object and fill with data using data adapters Fill method
        Dim dsp As DataSet = New DataSet
        dap.Fill(dsp, "main")

         Attach datasets DefaultView to the datagrid control
        Dim dvp As DataView = dsp.Tables("main").DefaultView
        combobox1.DataSource = dvp
        combobox1.DisplayMember = "Problem"
       msgbox (combobox1.item(0)) <-- problem here
the error msg is
An unhandled exception of type System.ArgumentException occurred in microsoft.visualbasic.dll

Additional information: Argument Prompt cannot be converted to type String.

pls..help me..thankss
 
Last edited by a moderator:
Try this...
Code:
the displayed text
MessageBox.Show(cboCustomers.SelectedValue.ToString)

or for its index position in the the control
MessageBox.Show(cboCustomers.SelectedIndex.ToString)

or even
MessageBox.Show(cboCustomers.Text)
 
thanks... but my problem is that, i have the index of the combo box. So i need to set the combo box to the value of its index.
i need something like this.

combobox.text = combobox.item(index)

but tht problem is combobox cannnot support combobox.item(index) if i use databinding...

it work fine if i do it like this.
combo.item.add("1")
combo.item.add("2")
combo.item.add("3")
msgbox combo.item(0)

so..any suggestion??
 
sorry..its cant work either, the text shows "System.Data.DataRowView" , what does this mean? what i want is the text of the specified index.....can some one pls help me
 
Last edited by a moderator:
When you set the DataSource you also need to set the ...
.DisplayMember = "SomeTextToShow"
.ValueMember = "SomeID"

The above SomeXXX are field names from your table.
 
emm.. wad should i put "someid" em.. i put "someid" wif the id of the field... and the data should be 1,2,3... and so on..but it cant work either.. what i wan is like this...

for example.
the record is
name = "alan"
value = 1
i have value = 1 and now i wan the combo box to display kevin. i can do tht by combobox.text = combobox.item(1) if i didnt use databinding..but it failed if i use databinding...

i really new to this..please help me..and sorry for disturbing your guys for so long
 
Last edited by a moderator:
so.. no body help me here.. i think i going to go throught the database to set the text..which is quite tedious to do....hai...
 
What are the two fields called in table? Are they name and ID ?
If so, then just do this...

Code:
With ComboBox1
    .DataSource = dvp
    .DisplayMember = "name"
    .ValueMember = "ID"
end with
 
but i still get "System.Data.DataRowView" when i put combobox.item(value). I pretty sure i put the correct one for displaymember and .valuemember because i get the corrent value when i use combobox.SelectedValue.ToString command.
 
em... i think my problem cant b solved here..thanks anyway.. i think i going to retrive the value in database to do it in the combo box again..thanks Robby..
 
Back
Top