开发者

Why does combo-box return the wrong value?

When I run my program and get it to give me the value (Yes, I do have the items in the drop down l开发者_JAVA百科ist selected) in the combo-box all I get is this,

System.Windows.Forms.ComboBox+ObjectCollection

This is the code I am using

 Dim name As String
        name = cmbworld.Text
        MsgBox(name)

Any ideas?

P.S. The code I used to insert the values is

cmbworld.Items.Clear()

     If File.Exists(root + "\setting\world.txt") Then
        For Each line As String In File.ReadLines(root + "\setting\world.txt")
            If line.Length <> 0 Then
                cmbworld.Items.Add(line)
            End If
        Next line
    Else


This code would reproduce the problem:

    Dim name As String
    name = cmbworld.Items.ToString()
    MsgBox(name)

You have some other code somewhere that is assigning the value of the Text property incorrectly. You need to index the Items collection. For example:

    cmbworld.Text = cmbWorld.Items(0)


The code you are posting can't be what is not working in your code.

Taking your example, I get a clean message with a line of data from my text file.

The only way I get your message is when I do the following:

MessageBox.Show(cmbworld.Items.ToString)

I would put a stop debugger on that MsgBox line and check the values.


You are using the wrong property, use SelectedText.

cmbworld.SelectedText

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜