VB.NET - working with LINQ using Custom Objects



Binding grid using custom properties and LINQ

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'get files from current directory 
        Dim Files = From file In My.Computer.FileSystem.GetFiles(CurDir)
                    Order By file
                    Select file
        Dim Filesinfo = From File In Files Select My.Computer.FileSystem.GetFileInfo(File)
        'Project results of query in custom objects
        Dim MyFiles = From file In Filesinfo
        Select New myFile With {.CreatTime = file.CreationTime, .Name = file.Name}
        DataGridView1.DataSource = MyFiles.ToList()
    End Sub
  

Declare Properties

        Private Class myFile
                Private Creationtime As DateTime
        Public Property CreateTime() As DateTime
            Get
                Return Creationtime
            End Get
            Set(ByVal value As DateTime)
                Creationtime = value
            End Set
        End Property

        Private m_name As String
        Public Property Name() As String
            Get
                Return m_name
            End Get
            Set(ByVal value As String)
                m_name = value
            End Set
        End Property

        Property CreatTime As Date
    End Class

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.