Rabu, 13 November 2019

Cara Membuat Tabel Data (GridView) Pada Report Gambas


Pada gb.Report2 tidak disediakan fitur ReportGridview untuk membuat tabel pada report, maka pembuatannya harus dilakukan secara manual yng melibatkan beberapa object yaitu ReportHBox, ReportVBox, ReportLabel/ReportTextLabel.

Berkut contoh script code pembuatan GridView pada Report

Pertama-tama buat dulu object Report. Jika belum mengerti cara pembuatan object Report bisa pelajari di sini:



Kode pada Class Report:


' Gambas class file

Private ReportHBox1 As ReportHBox

Private BarisIsi As Object[]
Private KolomIsi As Object[]

Private ReportTextLabel1 As ReportTextLabel


Public Sub Report_Open()

   Dim nb, nk As Byte
   Dim Nama As String[] = ["Bejo", "Ponimin", "Rukmini", "Iyum", "Sulastri"]
   Dim Alamat As String[] = ["Malang", "Pasuruan", "Nganjuk", "Blitar", "Sorong"]
   BarisIsi = New Object[Nama.Count]
   KolomIsi = New Object[Nama.Count, 3]
   '-------------------- Kepala Tabel
   ReportHBox1 = New ReportHBox(Report1)
   ReportHBox1.Border.Top.Width = 1
   ReportHBox1.Border.bottom.Width = 1
   ReportTextLabel1 = New ReportTextLabel(ReportHBox1)
   ReportTextLabel1.Width = 40
   ReportTextLabel1.Height = 20
   ReportTextLabel1.Text = "No"
   ReportTextLabel1.Background = ReportBrush.Color(&H00FFFF)
   ReportTextLabel1 = New ReportTextLabel(ReportHBox1)
   ReportTextLabel1.Width = 150
   ReportTextLabel1.Height = 20

   ReportTextLabel1.Text = "Nama"
   ReportTextLabel1.Background = ReportBrush.Color(&H9EC5EC)
   ReportTextLabel1 = New ReportTextLabel(ReportHBox1)
   ReportTextLabel1.Width = 300
   ReportTextLabel1.Height = 20
   ReportTextLabel1.Text = "Alamat"
   ReportTextLabel1.Background = ReportBrush.Color(&HFFFF00)
   '-------------------- Isi Tabel
   For nb = 0 To Nama.Max
     BarisIsi[nb] = New ReportHBox(Report1)
     For nk = 0 To 2
       KolomIsi[nb, nk] = New ReportTextLabel(BarisIsi[nb])
       KolomIsi[nb, nk].Height = 20
       If nk = 0 Then
         KolomIsi[nb, nk].Width = 40
         KolomIsi[nb, nk].Text = nb + 1
       Else If nk = 1 Then
         KolomIsi[nb, nk].Width = 150
         KolomIsi[nb, nk].Text = Nama[nb]
       Else If nk = 2 Then
         KolomIsi[nb, nk].Width = 300
         KolomIsi[nb, nk].Text = Alamat[nb]
       Endif
     Next
   Next

End

Tidak ada komentar:

Posting Komentar