Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i like to insert data from textbox and try getting displaying to datagridview by using datatable,
i can make success on first row but have problem on second row and ect because data gridview only displayed last input, What target is, i am going to input with different data for each row, please advice the solution Thanks...

What I have tried:

VB
Private Sub Create_VTableSell()
        Dim vRow As System.Data.DataRow
        Dim i As Integer
        VTablepenjualan = New DataTable
        VTablepenjualan.Columns.Add("Name_Items", GetType(String))
        VTablepenjualan.Columns.Add("Qty", GetType(Integer))
        VTablepenjualan.Columns.Add("Price", GetType(Double))
        VTablepenjualan.Columns.Add("Disc%", GetType(Double))
        VTablepenjualan.Columns.Add("Sub_Total", GetType(Double))
        VTablepenjualan.Columns.Add("Mode", GetType(String))
        'Try
        For i = 0 To DataGridView1.Rows.Count - 0
            'If IsDBNull(DataGridView1.Rows) Then Exit Sub
            vRow = VTableSell.NewRow
            vRow.Item(0) = TextBox4.Text
            vRow.Item(1) = TextBox5.Text
            vRow.Item(2) = TextBox6.Text
            vRow.Item(3) = TextBox7.Text
            vRow.Item(4) = TextBox5.Text * TextBox6.Text
            vRow.Item(5) = ComboBox1.Text
            VTableSell.Rows.Add(vRow)
        Next
         DataGridView1.Refresh()
        'Catch ex As Exception
        'End Try
    End Sub
Posted
Updated 3-Dec-16 0:29am
v2
Comments
Michael_Davies 3-Dec-16 6:28am    
You are adding the contents of a set of text boxes, the content of the text boxes does not change between each iteration of the loop.

Counts are zero based so you would normally iterate the DataGridView1.Rows.Count - 1 or you might get an out of range index exception.

Where are VTableSell and VTablepenjualan, you create VTablepenjualan and never seem to use it.
Dargombes Romadlon 3-Dec-16 10:24am    
i was thinking problem on loop but do not know where exactly
i have been tried to put rows.count-1 but the datagridview doesn't display any data

vTableSell is sub name, vTablepenjualan was declare earlier..
Michael_Davies 3-Dec-16 10:31am    
The loop is tied to the number of rows in the DataGridView1, how many records are there? Use the debugger to walk the code through and see what is happening.
Dargombes Romadlon 3-Dec-16 10:44am    
will be a lot of record because it purposed to creating per row in one record, some how i didn't see any error show up
Michael_Davies 3-Dec-16 11:12am    
Okay as it is not clear change the loop line to the following and see what happens, then use the debugger to walk thru and see what is happening and work out what is wrong.

For i = 0 to 10

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