Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

below is my source code.. i'm 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?

       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 adapter's Fill method
       Dim dsp As DataSet = New DataSet
       dap.Fill(dsp, "main")

       ' Attach dataset's 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

Edited by Robby
  • Moderators
Posted

Try this...

'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)

Visit...Bassic Software
Posted

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??

Posted (edited)
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 Edited by ribbysmurf
Posted (edited)

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

Edited by ribbysmurf
  • Moderators
Posted

What are the two fields called in table? Are they 'name' and 'ID' ?

If so, then just do this...

 

With ComboBox1
   .DataSource = dvp
   .DisplayMember = "name"
   .ValueMember = "ID"
end with

Visit...Bassic Software
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...