loading...

loading...

Tutor Kali ini Saya ingin berbagi cara add data dari gridview dan di insertkan ke gridview lain . Asumsikan kita akan membuat data delivery Order dimana data delivery order kita add berdasarkan dari Data SO (Sales Order) , pada menu Delivery order kita klik Tombol Browser nanti muncul List SOnya , ketika kita klik 2x So Pada Gridview di Form SO maka  akan otomatis menambah pada gridview form Delivery Order. ini hanya Asumsi saja , selebihnya silahkan Impelmentasikan sendiri yah.

Ok kita buat project baru dan buat 2 form , kemudian siapkan toolboxnya.
screenshot_1 screenshot_2 screenshot_3

Pertama Kita buat Codingan Pada form Delivery Order, Kta buat sub function

Sub HEADER_TEXT()
   With DGVX1
      .Columns.Add(0, "ITEM CODE")
      .Columns.Add(1, "ITEM DESC")
      .Columns.Add(2, "QTY SO")
      .Columns.Add(3, "Unit")
      .Columns.Add(4, "CUST.CODE")
   End With
End Sub

Kemudian Kita panggil Sub Function di atas pada FormLoad Delivery Ordernya

Private Sub DeliveryOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Call HEADER_TEXT()
End Sub

Setelah Itu klik 2x pada button Browse , jadi ketika di brows maka Listdata So terbuka atau Form SO terbuka ,

Private Sub Btn_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Browse.Click
ListDocuments.Show()
End Sub

jadi di form Delivery Order jika kita lihat ada codingan berikut.

Imports System.Data.Odbc
Imports System.Data.SqlClient
Public Class DeliveryOrder
    Sub HEADER_TEXT()
        With DGVX1
             .Columns.Add(0, "ITEM CODE")
             .Columns.Add(1, "ITEM DESC")
             .Columns.Add(2, "QTY SO")
             .Columns.Add(3, "Unit")
             .Columns.Add(4, "CUST.CODE")
       End With
    End Sub
Private Sub DeliveryOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     Call HEADER_TEXT()
End Sub

Private Sub Btn_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Browse.Click
     ListDocuments.Show()
End Sub

End Class

Ok ,Kemudian Kita Buat Codingan Di form SO,
Buat sub function Get data dari database ke Gridview SalesOrder

Sub GetData()
        Call BukaDB()
        cmd = New OdbcCommand(" Select * from tbl_sales_order Where TransStatus='1'", conn)
        da = New OdbcDataAdapter(cmd)
        ds = New DataSet
        ds.Clear()
        da.Fill(ds, "tbl_sales_order")
        BindingSource1.DataSource = ds.Tables("tbl_sales_order")
        BindingNavigator1.BindingSource = BindingSource1
        DGVX1.DataSource = BindingSource1
 End Sub

Kemudian Buat klik 2x pada Gridview Sales Order , dan pilih event CellDoubleClic ,
Jadi biar pada saat kita klik 2x pada gridview sales order maka data yang ada di gridview SO di tambahkan ke Gridview Delivery Order,

Private Sub DGVX1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVX1.CellDoubleClick
        Dim i As Integer = DGVX1.CurrentRow.Index
        Dim y As Integer = DeliveryOrder.DGVX1.Rows.Add
        DeliveryOrder.DGVX1.Rows.Item(y).Cells(0).Value = DGVX1.Item(0, i).Value
        DeliveryOrder.DGVX1.Rows.Item(y).Cells(1).Value = DGVX1.Item(1, i).Value
        DeliveryOrder.DGVX1.Rows.Item(y).Cells(2).Value = DGVX1.Item(2, i).Value
        DeliveryOrder.DGVX1.Rows.Item(y).Cells(3).Value = DGVX1.Item(3, i).Value
        DeliveryOrder.DGVX1.Rows.Item(y).Cells(4).Value = DGVX1.Item(4, i).Value
    End Sub

kemudian panggil sub fungction Getdata yg di buat tadi pada formLoad SO

 Private Sub ListDocuments_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call GetData()
    End Sub

Ok penampakan Fullnya pada Form SO ada di bawah ini.

Imports System.Data.Odbc
Imports System.Data.SqlClient
Public Class ListDocuments
  Sub GetData()
       Call BukaDB()
       cmd = New OdbcCommand(" Select * from tbl_sales_order Where TransStatus='1'", conn)
       da = New OdbcDataAdapter(cmd)
       ds = New DataSet
       ds.Clear()
       da.Fill(ds, "tbl_sales_order")
       BindingSource1.DataSource = ds.Tables("tbl_sales_order")
       BindingNavigator1.BindingSource = BindingSource1
       DGVX1.DataSource = BindingSource1
  End Sub
  Private Sub ListDocuments_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Call GetData()
  End Sub
  Private Sub DGVX1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVX1.CellDoubleClick
       Dim i As Integer = DGVX1.CurrentRow.Index
       Dim y As Integer = DeliveryOrder.DGVX1.Rows.Add
       DeliveryOrder.DGVX1.Rows.Item(y).Cells(0).Value = DGVX1.Item(0, i).Value
       DeliveryOrder.DGVX1.Rows.Item(y).Cells(1).Value = DGVX1.Item(1, i).Value
       DeliveryOrder.DGVX1.Rows.Item(y).Cells(2).Value = DGVX1.Item(2, i).Value
       DeliveryOrder.DGVX1.Rows.Item(y).Cells(3).Value = DGVX1.Item(3, i).Value
       DeliveryOrder.DGVX1.Rows.Item(y).Cells(4).Value = DGVX1.Item(4, i).Value
  End Sub
End Class

Coba running Projectnya,

Semoga Membantu.

 

 

 

Cara Add Data Antar Gridview Vb.Net (2010)
Share This
FacebookTwitterGoogle+WhatsAppEmailPrintFriendly
loading...

Post navigation


2 thoughts on “Cara Add Data Antar Gridview Vb.Net (2010)

  1. gan kalau coding memakai button gimana? jadi bukan pada saat cell double click baru data terisi, tapi maunya pada saat suata button di click baru data terisi. itu gimana codingnya gan? thanks

    1. sori gan baru buka blog lagi
      tinggal kodingan ini pindahin ke button

      Dim y As Integer = Me.DGVX1.Rows.Add
      Me.DGVX1.Rows.Item(y).Cells(0).Value = textbox1.text
      Me.DGVX1.Rows.Item(y).Cells(1).Value = textbox2.text
      Me.DGVX1.Rows.Item(y).Cells(2).Value = textbox3.text
      Me.DGVX1.Rows.Item(y).Cells(3).Value = textbox4.text
      Me.DGVX1.Rows.Item(y).Cells(4).Value = textbox5.text

      di atas bermaksud untuk memasukan value pada grid dari textbox

Leave a Reply

Your email address will not be published. Required fields are marked *