Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PASSING VALUE OF DATAGRIDVIEW TO OTHER FORM DATAGRIDVIEW IN VB.NET

What I have tried:

Try
            Dim dt2 As New DataTable

            dt2.Columns.Add("Metal", Type.GetType("system.string"))
            dt2.Columns.Add("Discription", Type.GetType("system.string"))
            dt2.Columns.Add("Huid", Type.GetType("system.string"))
            dt2.Columns.Add("Hsn", Type.GetType("system.string"))
            dt2.Columns.Add("Qty", Type.GetType("system.string"))
            dt2.Columns.Add("Unit", Type.GetType("system.string"))
            dt2.Columns.Add("GrossWt", Type.GetType("system.string"))
            dt2.Columns.Add("StoneWt", Type.GetType("system.string"))
            dt2.Columns.Add("NetWt", Type.GetType("system.string"))
            dt2.Columns.Add("Wastage", Type.GetType("system.string"))
            dt2.Columns.Add("Rate", Type.GetType("system.string"))
            dt2.Columns.Add("Mc", Type.GetType("system.string"))
            dt2.Columns.Add("Amount", Type.GetType("system.string"))


            For Each Row As DataGridViewRow In datagriditemdiscrib.Rows
                For i As Integer = 0 To datagriditemdiscrib.Rows.Count - 2 Step +1
                    dt2.Rows.Add(Row.Cells(0).Value, Row.Cells(1).Value, Row.Cells(2).Value, Row.Cells(3).Value, Row.Cells(4).Value, Row.Cells(5).Value, Row.Cells(6).Value, Row.Cells(7).Value, Row.Cells(8).Value, Row.Cells(9).Value, Row.Cells(10).Value, Row.Cells(11).Value, Row.Cells(12).Value)

                Next

            Next



        Catch ex As Exception
            MsgBox(ex.Message)
        End Try



        Invoice_print.Show()
        Invoice_print.datagriditemdiscrib_print.DataSource = dt2
Posted
Updated 9-Nov-22 5:44am

1 solution

If you'd actually tried debugging your code, you would have seen that Type.GetType("system.string") returns Nothing, which is why you are getting that error.

Either change the code to use Type.GetType("System.String") (notice the uppercase "S" for both words); or preferably to GetType(String), which will be faster.

GetType Operator - Visual Basic | Microsoft Learn[^]
 
Share this answer
 

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