Click here to Skip to main content
15,041,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...

I am new to vb.net. I need a help.

I have three DataGridView on my form. And I am importing the data from the csv to datagridview1 and datagridview2 and have 5 columns each with different Header. Now I need to copy first row cell calues from datagridview1 and datagridview2 to datagridview3 in the first row only. How can i perform this.

datagridview-1

Col-A : Col-B : Col-C
100 200 300
600 700 800


datagridview-2

Col-D : Col-E : Col-F
1000 2000 3000
6000 7000 8000


datagridview-3

Col-A : Col-B : Col-C : Col-D : Col-E : Col-F Total
100 200 300 1000 2000 3000 (C+F)
600 700 800 6000 7000 8000 (C+F)


The code which I am using to import CSV file to DATAGRIDVIEW.
VB
If System.IO.File.Exists(EquityReport) Then
    ReportListBox1.Items.AddRange(System.IO.File.ReadAllLines(EquityReport))
End If


''Code is responsible for updating the Filtered data to CSV
Dim myCoolWriter As New IO.StreamWriter(EquityReport)

For Each coolItem In ReportListBox1.Items
    myCoolWriter.WriteLine(coolItem)
Next

myCoolWriter.Close()

ReportListBox1.Update()


Dim dt As New DataTable


For Each line As String In System.IO.File.ReadAllLines("C:\TrendZ-Master\EquityReport.txt")

    DataGridView1.Rows.Add(line.Split(";"))
Next

For Each line As String In System.IO.File.ReadAllLines("C:\TrendZ-Master\EquityReport.txt")

    DataGridView2.Rows.Add(line.Split(";"))
Next
Posted
Updated 8-Jul-13 0:56am
v2

1 solution

try this
VB
Dim i As Integer = 0
        While i < DataGridView1.ColumnCount
            DataGridView3.Columns.Add(DataGridView1.Columns(i).HeaderText, DataGridView1.Columns(i).HeaderText)
            i += 1
        End While
        i = 0
        While i < DataGridView2.ColumnCount
            DataGridView3.Columns.Add(DataGridView1.Columns(i).HeaderText, DataGridView1.Columns(i).HeaderText)
            i += 1
        End While
        i = 0
        While i < DataGridView2.RowCount
            DataGridView3.Rows.Insert(DataGridView1.Item(0, i).Value, DataGridView1.Item(1, i).Value, DataGridView1.Item(2, i).Value, DataGridView2.Item(0, i).Value, DataGridView2.Item(1, i).Value, DataGridView2.Item(2, i).Value)
            i += 1
        End While

then you can perform your addition
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900