tagCANDY CGI VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
[ツリー表示へ]  [ワード検索]  [Home]

タイトル Re: コンボボックスのドロップダウンについて
投稿日: 2008/11/29(Sat) 17:05
投稿者魔界の仮面弁士
Imports KeyValue = System.Collections.Generic.KeyValuePair(Of String, String)
Public Class Form1

    Private list As New List(Of KeyValue)()

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        list.Add(New KeyValue("001", "value1"))
        list.Add(New KeyValue("002", "value2"))
        list.Add(New KeyValue("003", "value3"))
        list.Add(New KeyValue("004", "value4"))
        list.Add(New KeyValue("005", "value5"))
        list.Add(New KeyValue("006", "value6"))
        list.Add(New KeyValue("007", "value7"))
        list.Add(New KeyValue("", Nothing))

        'こうすると、空白を選択させた状態にすることすらできないはず。
        ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
        ComboBox1.DataSource = list.ToArray()
        ComboBox1.DisplayMember = "Value"
        ComboBox1.ValueMember = "Key"
        ComboBox1.Text = ""

        'sio さんの「空白が選択されてしまう」状態はこれかな?
        ComboBox2.DropDownStyle = ComboBoxStyle.DropDownList
        ComboBox2.DataSource = list.ToArray()
        ComboBox2.DisplayMember = "Value"
        ComboBox2.ValueMember = "Key"
        ComboBox2.SelectedValue = ""

        'で、こういう状態になればよいのかな?
        ComboBox3.DropDownStyle = ComboBoxStyle.DropDownList
        ComboBox3.DataSource = list.ToArray()
        ComboBox3.DisplayMember = "Value"
        ComboBox3.ValueMember = "Key"
        ComboBox3.SelectedIndex = -1
    End Sub

    Private Sub UpdateLabel(ByVal sender As Object, ByVal e As EventArgs) Handles _
        ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged, ComboBox3.SelectedIndexChanged, _
        ComboBox1.GotFocus, ComboBox2.GotFocus, ComboBox3.GotFocus

        Dim combo As ComboBox = DirectCast(sender, ComboBox)

        Label1.Text = String.Format("Name={0},Index={1},Value={2},Text={3}".Replace(",", vbNewLine), _
            combo.Name, combo.SelectedIndex, combo.SelectedValue, combo.SelectedText)
    End Sub
End Class

- 関連一覧ツリー をクリックするとツリー全体を一括表示します)

古いスレッドにレスはつけられません。