Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents Seiji Mori Presents

MSFlexGrid

’** 行数、列数の指定 **
With MSFlexGrid1
  .Rows = 100
  .Cols = 5
End With
 

’** 固定行、列の指定 **
With MSFlexGrid1
  .FixedCols = 2
  .FixedRows = 0
End With
 

’** セルに入力する **
 ’行番号、列番号ともに、0から始まる
MSFlexGrid1.TextMatrix(0, 0) = "日数"
 

’** 選択されたセルの値を得る **
Text_Edit.Text = MSFlexGrid1.Text
 

’** 内容の消去 **
MSFlexGrid1.Clear
 

’** セルの選択 **
With MSFlexGrid1
  .Row = 1 ’最初のセルの行番号
  .Col = 1 ’最初のセルの列番号
  .RowSel = 1 ’最後のセルの行番号
  .ColSel = 1 ’最後のセルの列番号
End With
 

’** 全データを指定 **
Dim TempText As String
With MSFlexGrid1
  .Row = 0
  .Col = 0
  .RowSel = .Rows - 1
  .ColSel = .Cols - 1
End With
TempText = MSFlexGrid1.Clip
 

’** 選択したセルの値を設定 **
With MSFlexGrid1
  .RowSel = .Row + IRow - 1
  .ColSel = .Col + ICol - 1
  .Clip = TempText
End With
 

’** 選択したすべてのセルに適用する **
MSFlexGrid1.FillStyle = flexFillRepeatすべてのセルに適用させる
MSFlexGrid1.Text = ""
MSFlexGrid1.FillStyle = flexFillSingle ’アクティブなセルだけに適用(規定)
 

’** セルの色を変える **
With MSFlexGrid1
  ’列全体の色を変える(灰色)
  For i = 0 To .Rows - 1
    .Col = 0
    .Row = i
    .CellBackColor = &HE0E0E0
  Next i
 
  ’行全体の色を変える
  For i = 0 To .Cols - 1
    .Col = i
    .Row = 0
    .CellBackColor = &HE0E0E0
  Next i
End With
 

’** MSFlexGridの位置、セルの位置、セルの大きさ **
With Text_Edit
  .Top = MSFlexGrid1.Top + MSFlexGrid1.CellTop
  .Left = MSFlexGrid1.Left + MSFlexGrid1.CellLeft
  .Height = MSFlexGrid1.CellHeight
  .Width = MSFlexGrid1.CellWidth
End With
 

’** 行幅、列幅を自由に変更できるようにする **
With MSFlexGrid1
  .AllowUserResizing = 3 '行列幅を自由に変更できる
End With

 
’** 行幅列幅の指定 **
With MSFlexGrid1
  .ColWidth(0) = 400 '列幅指定
  .RowHeight(-1) = 300 '行幅指定(-1で全部を変更
End With

 
'Deleteキーが押された場合
'** キーボート認識のためのAPI **
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const VK_DELETE = &H2E '[Delete]
 
Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
  If GetKeyState(VK_DELETE) < 0 Then
    MSFlexGrid1.FillStyle = flexFillRepeat
    MSFlexGrid1.Text = ""
    Text_Edit.Text = ""
    MSFlexGrid1.FillStyle = flexFillSingle
  End If
End Sub
 

’マウスでクリックした行・列番号を得る
’** マウスの右クリックで、ポップアップメニューを表示させる **
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = vbRightButton Then
    With MSFlexGrid1
      If .Row = .RowSel And .Col = .ColSel Then
      'セルが複数選択してない場合
        If .MouseRow > .FixedRows - 1 And .MouseCol > .FixedCols - 1 Then
          .Row = .MouseRow
          .Col = .MouseCol
        Else '固定行の場合
          Exit Sub
        End If
 
        PopupMenu Edit
      Else
      'セルが複数選択してある場合
        If .Row <= .MouseRow And .MouseRow <= .RowSel _
          And .Col <= .MouseCol And .MouseCol <= .ColSel Then
          マウスが範囲内にある場合
 
          PopupMenu Edit
 
        Else
        'マウスが範囲外にある場合
          If .MouseRow > .FixedRows - 1 And .MouseCol > .FixedCols - 1 Then
            .Row = .MouseRow
            .Col = .MouseCol
          Else
            Exit Sub
          End If
 
          PopupMenu Edit
        End If
 
      End If
    End With
  End If
 
End Sub
 

’** セル内の文字や数字の配置位置 **
With MSFlexGrid1
  .ColAlignment(0) = 1 '配置(左中央、文字の既定値)
  .ColAlignment(1) = 7 '配置(右中央、数値の既定値)
End With
 
定数 値 内容
flexAlignLeftTop 0 列の内容は左上に配置されます。
flexAlignLeftCenter 1 文字列の既定値です。列の内容は左中央に配置されます。
flexAlignLeftBottom 2 列の内容は左下に配置されます。
flexAlignCenterTop 3 列の内容は中央上に配置されます。
flexAlignCenterCenter 4 列の内容は中央の中央に配置されます。
flexAlignCenterBottom 5 列の内容は中央下に配置されます。
flexAlignRightTop 6 列の内容は右上に配置されます。
flexAlignRightCenter 7 数値の既定値です。列の内容は右中央に配置されます。
flexAlignRightBottom 8 列の内容は右下に配置されます。
flexAlignGeneral 9 列の内容は通常の方法で配置されます。つまり、文字列は左中央に配置され、数値は右中央に配置されます。