Arg81
Well-known member
Good morning,
I am exporting a datagridview to a text file. The code to do this is:
One of the columns is a date field. Visually it displays the date how I want it (e.g. 18 December 2009)
however when it is exported to the text file the format is 18/12/2009 00:00:00
This text file is then used on a mail merge to a document to produce some labels.
Obviously I don't want the time shown.
Is there a way to remove this during the export?
I am exporting a datagridview to a text file. The code to do this is:
VB.NET:
Public Sub WriteTextFile(ByVal dgv As DataGridView, ByVal varlbl As String)
Dim strExport As String = ""
[COLOR="seagreen"] 'Loop through all the columns in DataGridView to Set the Column Heading[/COLOR]
For Each dc As DataGridViewColumn In dgv.Columns
strExport += dc.Name.Substring(0) & "*"
Next
strExport = strExport.Substring(0) + Environment.NewLine.ToString()
[COLOR="seagreen"] 'Loop through all the row and append the value with 3 spaces[/COLOR]
For Each dr As DataGridViewRow In dgv.Rows
For Each dc As DataGridViewCell In dr.Cells
If dc.Value IsNot Nothing Then
strExport += dc.Value.ToString() & "*"
End If
Next
strExport += Environment.NewLine.ToString()
Next
[COLOR="seagreen"] 'Create a TextWrite object to write to file, varlbl is the txt file to export to[/COLOR]
Dim tw As System.IO.TextWriter = New System.IO.StreamWriter(varlbl)
[COLOR="seagreen"]'Write the Text to file[/COLOR]
tw.Write(strExport)
[COLOR="SeaGreen"] 'Close the Textwrite[/COLOR]
tw.Close()
End Sub
One of the columns is a date field. Visually it displays the date how I want it (e.g. 18 December 2009)
however when it is exported to the text file the format is 18/12/2009 00:00:00
This text file is then used on a mail merge to a document to produce some labels.
Obviously I don't want the time shown.
Is there a way to remove this during the export?