C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト


(過去ログ 122 を表示中)
■72834 / )  Re[3]: コンボボックスの初期値指定をしたい
□投稿者/ King (1回)-(2014/07/23(Wed) 11:25:51)
提示のコードだと FLG は SelectedIndexChanged イベントハンドラ内は
スコープ外なのでビルドエラーになりますよね?

やりたいことはこういうことですか?

Private _isLoading As Boolean = False

Private Sub FmA_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Try
        _isLoading = True
        
        With ComboBox1
            .Items.Add("魚料理")
            .Items.Add("肉料理")
            .DropDownStyle = ComboBoxStyle.DropDownList
            .SelectedIndex = 0
        End With

        With ComboBox2
            .Items.Add("ミディアム")
            .Items.Add("レア")
            .DropDownStyle = ComboBoxStyle.DropDownList
            .SelectedIndex = 0
        End With
    Finally
        _isLoading = False
    End Try
End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    If _isLoading Then
        Return
    End If

    If ComboBox1.SelectedIndex = 0 Then
        With ComboBox2
            .SelectedIndex = 0 ※
            .Enabled = True
        End With
    End If

    If ComboBox1.SelectedIndex = 1 Then
        With ComboBox2
            .SelectedIndex = 1
            .Enabled = False
        End With
    End If
End Sub

返信 編集キー/


管理者用

- Child Tree -