Hi guys I am stuck on have a user enter data into a DGV and then creating a table out of that data. I need to know how to take the data the user enters into a DGV cell and have addded to the dgv so that it can then be added the a table here is what i got so far:


code Code:
  1. Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  2.         Me.DataGridView1.Show()
  3.         Me.DataGridView1.Columns.Add("FullStreetAddress", "FullStreetAddress")
  4.         Me.DataGridView1.Columns.Add("City", "City")
  5.         Me.DataGridView1.Columns.Add("State", "State")
  6.         Me.DataGridView1.Columns.Add("Zip", "Zip")
  7.         Me.DataGridView1.Columns.Add("Bedrooms", "Beds")
  8.         Me.DataGridView1.Columns.Add("Baths", "Baths")
  9.         Me.DataGridView1.Columns.Add("BuildingSize", "BuildingSize")
  10.         Me.DataGridView1.Columns.Add("Lot Size", "LotSize")
  11.         Me.DataGridView1.Columns.Add("ListPrice", "ListPrice")
  12.         Me.DataGridView1.Columns.Add("ListingDate", "ListDate")
  13.         Me.DataGridView1.Columns.Add("ListingType", "ListType")
  14.         Me.DataGridView1.Columns.Add("Latitude", "Latitude")
  15.         Me.DataGridView1.Columns.Add("Longitude", "Longitude")
  16.         Me.DataGridView1.Columns.Add("GLAMax", "GLAMax")
  17.  
  18.         With Me.DataGridView1.Rows
  19.             Dim row1 As String() = {Me.DataGridView1.Columns(0).Name, }
  20.  
  21.         End With
  22.     End Sub
  23.  
  24.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  25.         Dim dtlist As New DataTable()
  26.         dtlist = TryCast(DataGridView1.DataSource, DataTable)
  27.  
  28.     End Sub
  29.  
  30.     Public Shared Function DataGridViewToDataTable(ByVal dtg As DataGridView) As DataTable
  31.         Try
  32.             Dim dtlist As New DataTable()
  33.             Dim row As DataRow
  34.             Dim TotalDatagridviewcolumns As Integer = dtg.ColumnCount - 1
  35.  
  36.             For Each c As DataGridViewColumn In dtg.Columns
  37.                 Dim idColumn As DataColumn = New DataColumn()
  38.                 idColumn.ColumnName = c.Name
  39.                 dtlist.Columns.Add(idColumn)
  40.  
  41.             Next
  42.             For Each dr As DataGridViewRow In dtg.Rows
  43.                 row = dtlist.NewRow
  44.                 For cn As Integer = 0 To TotalDatagridviewcolumns
  45.                     row.Item(cn) = (dr.Cells(cn).Value)
  46.                 Next
  47.                 dtlist.Rows.Add(row)
  48.             Next
  49.  
  50.             Return dtlist
  51.         Catch ex As Exception
  52.             Return Nothing
  53.  
  54.         End Try
  55.     End Function