Hi to everybody!

Is anyone can help me how to add a row in datagrid in vb 6.0. I have three text box of data displayed in datagrid using a button addtocart.

The problem is when i click the addtocart button data in text box were displayed in datagrid but I dont know how to add another row in the datagrid for the another data to be displayed.

Thank you..

Elmer E. Estandarte

7 Years
Discussion Span
Last Post by AndreRet

Your datagrid is a databound control. You have to set it to a database. See the code below on how to do this. If you however do not want to add the textbox entries to a database, just add the text to a listbox.

List1.AddItem Text1.Text & "    " & Text2.Text

If you click on your command button to add another row, this will be -

List1.AddItem List1.Text & vbCrLf & Text1.Text & "  " & Text2.Text 'Where vbcrlf is you return carriage or Enter

With the datagrid you will have something like the following -

Private WithEvents cnShopCart As ADODB.Connection
Private WithEvents rsShopCart As ADODB.Recordset

'Add this to your command1_click event
cnShopCart.Open = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source=App.Path & "\MyDatabaseName.mdb"
  Set rsShopCart = New ADODB.Recordset
rsShopCart.Open "SELECT * FROM MyShopCartTableName", cnShopCart, adOpenStatic, adLockOptimistic

If rsShopCart.BOF = True Or rsShopCart.EOF = True Then
       Exit Sub
End If


rsShopCart!YourShopCartFieldName = Text1.Text

Set DataGrid1.DataSource = rsShopCart
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.