Question Convert String to DateTime in DGV

andrew229

New member
Joined
Aug 20, 2012
Messages
1
Programming Experience
Beginner
Hello.
I have a DGV that is being populated by a XML file as the datasource. I can't seem to figure out how to convert the data in the 2nd column from a string to a short date.
This is my DGV code:

VB.NET:
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim xmlFile As XmlReader
        xmlFile = XmlReader.Create("C:\Data.xml", New XmlReaderSettings())
        Dim ds As New DataSet
        ds.ReadXml(xmlFile)
        DataGridView1.DataSource = ds.Tables(0)
    End Sub

There are 6 columns in the DGV. I also would like to convert column 4 to a data type of "currency" .

Can anyone help me with this? I've looked at several examples online, but I can't seem to figure this out.

Thanks!
 
If you create a DataSet with the appropriate schema in the first place and then call its WriteXml method then it will write metadata into the XML to indicate what type each data item is. If you just use vanilla XML then everything is just text, so there is no reason for ReadXml to interpret it as anything else.
 
There are 6 columns in the DGV. I also would like to convert column 4 to a data type of "currency" .


VB.NET:
        With DGV
            .Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
            .Columns(3).DefaultCellStyle.Format = "###,##0.00"
        End With
 
Back
Top