Hola, estoy trabajando en un proyecto que debe exportar un datagrid hacia txt y lo he logrado, la cuestión es que debo eliminar la última coma de cada línea, intentando varias opciones sin resultados satisfactorios.
Private Sub btntxt57_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntxt57.Click
Const RUTA As String = "C:\Documents and Settings\Administrador\Mis documentos\Visual Studio 2005\Projects\consoft\consoft\bin\Debug\data.txt"
Dim strExport As String = ""
For Each dr As DataGridViewRow In dgv57.Rows
For Each dl As DataGridViewColumn In dgv57.Columns
If dr.Cells(dl.Name).Value IsNot Nothing And dl.HeaderText <> "Detalle" Then
strExport += dr.Cells(dl.Name).Value.ToString() + ","
End If
Next
'aquí he intentado con strimend, remove pero no he podido.
strExport += Environment.NewLine.ToString()
Next
strExport = strExport.Substring(0, strExport.Length - 3) + Environment.NewLine.ToString()
'Create a TextWrite object to writ7e to file, select a file name with .txt extention
Dim tw As System.IO.TextWriter = New System.IO.StreamWriter("data.txt")
'Write the Text to file
tw.Write(strExport)
'Close the Textwrite
tw.Close()
Process.Start(RUTA)
End Sub
Agradezco de antemano su gentil atención