0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

テスト83

Posted at
Option Explicit
'リストビュー関連

'ユーザーフォームを挿入
'ツールボックスで右クリック....〆(・ω・ )メモ
'「コントロールの追加」ウィンドウの中から「Microsogt ListView,version 6」を選択
Private Sub CommandButton1_Click()

Dim i As Long
Dim tmp As String
Dim Select_flg As Boolean

Select_flg = False

With ListView1.ListItems

    For i = 1 To .Count
        'チェックボックスにチェックがついた行を取得
        If ListView1.ListItems(i).Checked = True Then
    
            MsgBox .Item(i).SubItems(1) & .Item(i).SubItems(2)
            Select_flg = True

        End If
        
        '選択されている場合
        If ListView1.ListItems(i).Selected = True Then
            'リストの値を取得
            tmp = tmp & .Item(i).SubItems(1) & .Item(i).SubItems(2) & vbCrLf
            Select_flg = True

        End If
      
    Next

End With

'選択チェック
If Select_flg = False Then

    MsgBox "値が選択されていません。", vbCritical, "未選択"
    Exit Sub
    
End If

MsgBox tmp

End Sub

Private Sub CommandButton2_Click()

'チェックボックスを一括選択(解除)
'ラベルをボタンの下に入れて(ユーザーからは見えない)、その値で判定
Dim i As Integer

Application.ScreenUpdating = False

With ListView1

    For i = 1 To .ListItems.Count
    
        If Me.フラグ.Caption = 0 Then
        
            .ListItems(i).Checked = True
        
        Else
        
            .ListItems(i).Checked = False
        
        End If
       
     Next i
     
End With



If Me.フラグ.Caption = 0 Then
 
     Me.フラグ.Caption = 1
 
 Else
 
     Me.フラグ.Caption = 0
 
 End If

Application.ScreenUpdating = True

End Sub


Private Sub ListView1_BeforeLabelEdit(Cancel As Integer)

End Sub

Private Sub UserForm_Initialize()

Dim Last_Row As Long
Dim sh As Worksheet
Dim i As Long

Set sh = ThisWorkbook.Sheets("リスト")


'最終行取得
Last_Row = sh.Cells(Rows.Count, 1).End(xlUp).Row

With ListView1
    '初期設定
    .View = lvwReport           '一覧表示
    .Gridlines = True           'グリッド線の追加
    .FullRowSelect = True       '選択を行全体に変更
    .AllowColumnReorder = True  '列幅の変更を許可
    .HideSelection = True      '選択の自動解除
    .LabelEdit = lvwManual          'ラベル編集不可
    
    .ColumnHeaders.Clear
    .ColumnHeaders.Add 1, "ckBox", "", 15 ', lvwColumnLeft
    .ColumnHeaders.Add 2, "No", "No", 25 ', lvwColumnLeft
    .ColumnHeaders.Add 3, "ItemCategory", "商品カテゴリコード", 80 ', lvwColumnCenter
    .ColumnHeaders.Add 4, "ItemCode", "商品コード", 80 ', lvwColumnCenter
    .ColumnHeaders.Add 5, "KanriCode", "管理コード", 80 ', lvwColumnCenter
    .ColumnHeaders.Add 6, "Price", "価格", 80 ', 'lvwColumnCenter
    
    'データ挿入
    For i = 2 To Last_Row
    
        With .ListItems.Add

             .SubItems(1) = sh.Cells(i, 1)
             .SubItems(2) = sh.Cells(i, 2)
             .SubItems(3) = sh.Cells(i, 3)
             .SubItems(4) = sh.Cells(i, 4)
             .SubItems(5) = sh.Cells(i, 5)
             
         End With
         
     Next i
     
     .SelectedItem.Selected = False
     
End With

Me.フラグ.Caption = 0

End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?