I am saving textbox text to a DGV and then saving the DGV row to a xml file but i cannot workout how to append instead of overwriting.
Code:Public Sub WwriteToDataGridView() 'save data to DGV With Ddata.DataGridView2 'https://stackoverflow.com/questions/19162248/index-was-out-of-range-must-be-non-negative-And-less-than-the-size-of-the-colle ' Write to cell (0,0) '.ColumnCount = 6 .Columns(0).Name = "REGO" .Rows(0).Cells(0).Value = OEM_Specs.TxReg.Text .Columns(1).Name = "WHEELBASE" .Rows(0).Cells(1).Value = OEM_Specs.TxtWheelBase.Text .Columns(2).Name = "REAR OVERHANG" .Rows(0).Cells(2).Value = OEM_Specs.TxtReOverhang.Text 'gvm diff .Columns(3).Name = "GVM DIFF" .Rows(0).Cells(3).Value = TxtTBMeffectGVM.Text 'tbw .Columns(4).Name = "TBM" .Rows(0).Cells(4).Value = TxtTowBallMassVan.Text 'gvm gain/loss .Columns(5).Name = "GVM GAIN LOSS" Dim GVMVanEffect2 As Double = CDbl(TxtTBMeffectGVM.Text) Dim GgvmGainLoss As Double = TBM - GVMVanEffect2 .Rows(0).Cells(5).Value = GgvmGainLoss.ToString End With End SubCode:Public Sub SsaveDataGridViewToDataSet() Dim dt As DataTable = New DataTable("data") For i As Integer = 0 To Ddata.DataGridView2.ColumnCount - 1 dt.Columns.Add(Ddata.DataGridView2.Columns(i).Name, GetType(System.String)) Next Dim myrow As DataRow Dim icols As Integer = Ddata.DataGridView2.Columns.Count For Each drow As DataGridViewRow In Ddata.DataGridView2.Rows myrow = dt.NewRow() For i As Integer = 0 To icols - 1 myrow(i) = drow.Cells(i).Value Next dt.Rows.Add(myrow) Next dt.WriteXml(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\weights\data\data.xml") End Sub




Reply With Quote