ribbysmurf Posted August 17, 2003 Posted August 17, 2003 (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 August 17, 2003 by Robby Quote
Moderators Robby Posted August 17, 2003 Moderators Posted August 17, 2003 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) Quote Visit...Bassic Software
ribbysmurf Posted August 17, 2003 Author Posted August 17, 2003 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?? Quote
aewarnick Posted August 17, 2003 Posted August 17, 2003 this.imageFormatComB.Text= this.imageFormatComB.Items[2].ToString(); Quote C#
ribbysmurf Posted August 18, 2003 Author Posted August 18, 2003 (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 August 18, 2003 by ribbysmurf Quote
Moderators Robby Posted August 18, 2003 Moderators Posted August 18, 2003 When you set the DataSource you also need to set the ... .DisplayMember = "SomeTextToShow" .ValueMember = "SomeID" The above 'SomeXXX' are field names from your table. Quote Visit...Bassic Software
ribbysmurf Posted August 19, 2003 Author Posted August 19, 2003 (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 August 19, 2003 by ribbysmurf Quote
ribbysmurf Posted August 20, 2003 Author Posted August 20, 2003 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... Quote
Moderators Robby Posted August 20, 2003 Moderators Posted August 20, 2003 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 Quote Visit...Bassic Software
ribbysmurf Posted August 21, 2003 Author Posted August 21, 2003 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. Quote
Moderators Robby Posted August 21, 2003 Moderators Posted August 21, 2003 Please check my first post in this thread. Quote Visit...Bassic Software
ribbysmurf Posted August 21, 2003 Author Posted August 21, 2003 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.. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.