掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
コンボボックスについて (ID:115080)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
エラーメッセージの内容もエラーの起こった状況も 書かずにヒントをくれと言われても困るんですが?(^^;) とりあえずそこそこ動きそうなコードを載せますので自分で 気に入るように修正して下さい。 [VB6.0] '/////////// Form1 のコード Option Explicit Private Sub Form_Load() Call ComboListItemSet(Me.Combo1) Call ComboListItemSelect(Me.Combo1, 0) Form2.Show End Sub Public Sub Combo1ListItemDelete(ByVal DeleteIndex As Integer) Dim wSelectIndex wSelectIndex = Me.Combo1.ListIndex If wSelectIndex = DeleteIndex Then wSelectIndex = wSelectIndex - 1 End If Call ComboListItemDelete(Me.Combo1, DeleteIndex) Call ComboListItemSelect(Me.Combo1, wSelectIndex) End Sub '/////////// Form2 のコード Option Explicit Private Sub Command2_Click() Dim wDeleteIndex As Integer With Me.Combo2 If .ListIndex > -1 Then wDeleteIndex = .ListIndex Call ComboListItemDelete(Me.Combo2, wDeleteIndex) Call Form1.Combo1ListItemDelete(wDeleteIndex) Call ComboListItemSelect(Me.Combo2, wDeleteIndex - 1) End If End With End Sub Private Sub Form_Load() Call ComboListItemSet(Me.Combo2) Call ComboListItemSelect(Me.Combo2, 0) End Sub '/////////// Module1 のコード Option Explicit Public Sub ComboListItemSet(ByVal Combox As ComboBox) Dim i As Integer With Combox For i = 0 To 7 .AddItem ("項目" & CStr(i)) Next End With End Sub Public Sub ComboListItemSelect(ByVal Combox As ComboBox, ByVal Index As Integer) Dim i As Integer With Combox If .ListCount <= 0 Then Exit Sub ElseIf .ListCount < Index Then .ListIndex = .ListCount - 1 Else If Index = -1 Then Index = 0 End If .ListIndex = Index End If End With End Sub Public Sub ComboListItemDelete(ByVal Combox As ComboBox, ByVal Index As Integer) Dim i As Integer With Combox If Index < 0 Then Exit Sub ElseIf .ListCount < Index Then Exit Sub Else .RemoveItem Index End If End With End Sub
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.