PDA

Click to See Complete Forum and Search --> : Get Selected item in combox ??[Resolved]


Pirate
Mar 3rd, 2003, 01:23 AM
Am I losing my mind ??
I tried this but it sends me error :

MsgBox(ComboBox4.SelectedItem)

any thoughts plz ?

Pirate
Mar 3rd, 2003, 01:28 AM
the error says :
Can't be converted to 'String' ?? I tried Ctype fun and ToString but with this stupid error ?

I've just tried this but gives empy msgbox :

MsgBox(ComboBox4.SelectedText.ToString)
or
MsgBox(ComboBox4.SelectedText)

Edneeis
Mar 3rd, 2003, 01:42 AM
What type is the objects you are putting in the ComboBox? What do you have set as the DisplayMember of the Combo?

Pirate
Mar 3rd, 2003, 01:43 AM
Originally posted by Edneeis
What type is the objects you are putting in the ComboBox? What do you have set as the DisplayMember of the Combo?
I'm using this sub to load all tables in my db (your sub actually :D)


Public Shared Sub LoadTables(ByVal Combox As ComboBox)
Dim var As New Variables()
var.MyConnection.Open()
Dim Tables As DataTable = var.MyConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
var.MyConnection.Close()
Combox.DataSource = Tables
Combox.DisplayMember = "TABLE_NAME"
End Sub

Pirate
Mar 3rd, 2003, 01:46 AM
and this line in the form_load .

ComboBox4.DropDownStyle = ComboBoxStyle.DropDownList

Edneeis
Mar 3rd, 2003, 01:56 AM
That is wierd must be some kind of conversation problem. Try just using Combox.Text, since if the item is selected the it is the same as what selectedtext should be.

Pirate
Mar 3rd, 2003, 01:58 AM
lol :D . It's working now Edneeis ! thank you so much .
I've tried everything except this .

Pirate
Mar 3rd, 2003, 02:00 AM
Weird .. I can get selected items in other comboxes .I think if it is bounded , then it needs more code or whatever .But can you guess what's going wrong ??

Edneeis
Mar 3rd, 2003, 02:10 AM
No I'm not sure what the trouble is. I know even bound, you can usually get the SelectedText, but something about binding to a datatable directly or at least this one makes it not work.

Actually I thought I've used it before with a bound combo, but maybe not because it did the same thing when bound to an array of strings.

Pirate
Mar 3rd, 2003, 02:13 AM
It's a bug maybe .Thanx anyways for the help ! :)