Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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.
 
    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 8-Jul-13 1:53am
Edited 8-Jul-13 1:56am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try this
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
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 Andreas Gieriet 90
4 Jochen Arndt 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100