Melakukan Merge Column Header pada MSFlexGrid VB6


Pada tutorial kali ini akan dibahas cara melakukan merging pada kolom header MSFlexGrid pada vb6. Tutorial ini kami tulis mengingat masih banyak pertanyaan mengenai hal tersebut di internet. Langsung saja!

  1. Buat project baru (secara otomatis akan membuat form1)
  2. Tambahkan component Microsoft FlexGrid Control 6.0
  3. Tambahkan MSFlexGrid pada form1
  4. Click ‘view code‘ dan tambahkan kode berikut:


Private Sub Form_Load()
Caption = "Merging Kolom Header MSFlexGrid"
Call LoadSetting
With MSFlexGrid1
.TextMatrix(2, 0) = "1"
.TextMatrix(2, 1) = "B-001"
.TextMatrix(2, 2) = "BUKU TULIS"
.TextMatrix(2, 3) = "3500"
.TextMatrix(2, 4) = "4000"

.TextMatrix(3, 0) = "2"
.TextMatrix(3, 1) = "B-002"
.TextMatrix(3, 2) = "BUKU TULIS TEBAL"
.TextMatrix(3, 3) = "8500"
.TextMatrix(3, 4) = "9000"

.TextMatrix(4, 0) = "3"
.TextMatrix(4, 1) = "B-003"
.TextMatrix(4, 2) = "PENSIL KINKO"
.TextMatrix(4, 3) = "2500"
.TextMatrix(4, 4) = "3000"

End With
End Sub

Sub LoadSetting()
With MSFlexGrid1
.Cols = 5
.Rows = 5
.FixedRows = 2

.RowHeightMin = 300
.Col = 0
.Row = 0
.ColWidth(0) = 700
.CellAlignment = flexAlignCenterCenter
.ColAlignment(0) = flexAlignCenterCenter
.MergeCells = flexMergeRestrictAll
.MergeCol(0) = True
.TextMatrix(0, 0) = "NOMOR"
.TextMatrix(1, 0) = "NOMOR"

.RowHeightMin = 300
.Col = 1
.Row = 0
.ColWidth(1) = 1000
.CellAlignment = flexAlignCenterCenter
.ColAlignment(1) = flexAlignCenterCenter
.MergeCells = flexMergeRestrictAll
.MergeCol(1) = True
.TextMatrix(0, 1) = "ID BARANG"
.TextMatrix(1, 1) = "ID BARANG"

.RowHeightMin = 300
.Col = 2
.Row = 0
.ColWidth(2) = 2700
.CellAlignment = flexAlignCenterCenter
.MergeCells = flexMergeRestrictAll
.MergeCol(2) = True
.TextMatrix(0, 2) = "JENIS BARANG"
.TextMatrix(1, 2) = "JENIS BARANG"

.Col = 3
.Row = 0
.Text = "HARGA"
.ColWidth(3) = 1000
.MergeCells = flexMergeRestrictAll
.MergeRow(0) = True
.MergeRow(1) = False
.CellAlignment = flexAlignCenterCenter
.ColAlignment(3) = flexAlignCenterCenter
.TextMatrix(1, 3) = "BELI"

.Col = 4
.Row = 0
.Text = "HARGA"
.ColWidth(4) = 1000
.CellAlignment = flexAlignCenterCenter
.ColAlignment(4) = flexAlignCenterCenter
.TextMatrix(1, 4) = "JUAL"

End With
End Sub

Run program dengan menekan tombol F5, maka akan tampil seperti gambar berikut:

Selamat mencoba!

5 responses to “Melakukan Merge Column Header pada MSFlexGrid VB6

  1. gan kalo hide salah satu kolom di msflexgrid caranya gimana yah?? terima kasih..

  2. terima kasih gan, sesuai seperti yang diharapkan, tetapi hasilnya koq di kolom untung, baris 1,2,3 kalau valuenya sama ikut di merger, misal baris 1 5000, baris 2 dan sterusnya 5000, jadinya baris 123 di kolom untung menjadi 1 cell (merger). bisa kah kalau baris 123 di kolom untung tidak merger, cukup header “untung” yang merger?

  3. gan, kalo setelah kolom harga jual tadi mau kita tambahin 1 kolom lagi tapi headernya di merger bisa gak? misalkan kita kasih judul “keuntungan”, sebab yg saya coba, jika menambahkan kolom setelah harga jual tersebut headernya gak bisa merger (=alias tetap jadi 2 baris). thank u/ pencerahannya

    • Pastikan sudah menambah jumlah kolom pada code berikut
      With MSFlexGrid1
      .cols = 6

      Di bagian akhir, baru tambahkan header
      .Col = 5
      .Row = 0
      .ColWidth(5) = 1000
      .CellAlignment = flexAlignCenterCenter
      .ColAlignment(5) = flexAlignCenterCenter
      .MergeCells = flexMergeRestrictColumns
      .MergeCol(5) = True
      .TextMatrix(0, 5) = "UNTUNG"
      .TextMatrix(1, 5) = "UNTUNG"

      End With

      Selamat mencoba, semoga berhasil….

Write Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s