DataGridView daki Kayıtları Diğer DataGridView a Kopyalama
Bu örnekte DataGridView1 deki kayıtları DataGridView2 e kopyalayacağız. Aşağıdaki şekilleri inceleyin.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With DataGridView1
.ColumnCount = 4
.Columns(0).Name = "Adi"
.Columns(1).Name = "Meslegi"
.Columns(2).Name = "Ogrenim Durumu"
.Columns(3).Name = "Yasadigi Yer"
.Columns(0).DisplayIndex = 0
.Columns(1).DisplayIndex = 1
.Columns(2).DisplayIndex = 2
.Columns(3).DisplayIndex = 3
End With
DataGridView1.Columns(0).Width = 100
DataGridView1.Columns(1).Width = 100
DataGridView1.Columns(2).Width = 150
DataGridView1.Columns(3).Width = 130
Dim r1 As String() = {"Bahadirsa", "Mühendis", "Master", "Istanbul"}
Dim r2 As String() = {"Ali", "xxxxx", "xxxxx", "Istanbul"}
Dim r3 As String() = {"Veli", "xxxxx", "xxxxx", "Istanbul"}
Dim r4 As String() = {"KirkDokuz", "xxxxx", "xxxxx", "Istanbul"}
Dim r5 As String() = {"Elli", "xxxxx", "xxxxx", "Istanbul"}
With DataGridView1.Rows
.Add(r1)
.Add(r2)
.Add(r3)
.Add(r4)
.Add(r5)
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim satirsayi
Dim i
satirsayi = DataGridView1.RowCount
DataGridView2.RowCount = satirsayi
DataGridView2.ColumnCount = 6
i = 1
Do While True
DataGridView2.Rows(i - 1).Cells(0).Value = DataGridView1.Rows(i - 1).Cells(0).Value
DataGridView2.Rows(i - 1).Cells(1).Value = DataGridView1.Rows(i - 1).Cells(1).Value
DataGridView2.Rows(i - 1).Cells(2).Value = DataGridView1.Rows(i - 1).Cells(2).Value
DataGridView2.Rows(i - 1).Cells(3).Value = DataGridView1.Rows(i - 1).Cells(3).Value
If i = satirsayi Then
Exit Do
Else
i = i + 1
End If
Loop
End Sub
End Class
Bir sonraki makalede buluşmak üzere. Bahadır ŞAHİN