add new data on the next row?

vb_newb

Member
Joined
Jan 31, 2013
Messages
7
Programming Experience
Beginner
good day all

can u help me with this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click




Dim dt As New DataTable


dt.Columns.Add("Brand")
dt.Columns.Add("Quantity")
dt.Columns.Add("UnitPrice")


dt.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text)




DataGridView1.DataSource = dt
End Sub


after adding the datas to the columns, i want to add new data on the next row ..??
 

Attachments

  • trydatagridview.zip
    15.1 KB · Views: 20
Last edited by a moderator:
Hi,

If you declare your DataTable (dt) variable at the CLASS level then you can continue to call your own routine to add additional rows to the DataGridView. i.e:-

VB.NET:
dt.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text)

Hope that helps.

Cheers,

Ian
 
what i mean is when i click again the button, anything on the textbox even if its the same data it will save to the next row until i stop ..
 
Hi,

what i mean is when i click again the button, anything on the textbox even if its the same data it will save to the next row until i stop ..

If you do what I suggested then it will do this. To be a little clearer for you:-

1) Declare your DataTable variable at the Class level. - Do you know how to do this?

2) In the Form load event add the fields / columns to your DataTable. You only need to do this once, hence doing this in the Form Load event.

3) In the same Form Load event set the DataSource of the DataGridView to the DataTable variable. You only need to do this once.

4) Change the code in the Button to only contain the line of code that adds the row.

Hope the helps.

Cheers,

Ian
 
tnx a lot sir Ian... not it works.. tyvm for ur time.. sorry im too newb with this..




i have another question..


how can i get the sum of a column.??


edit: already found the solution ty again..
 
Last edited:
Back
Top