Programatically fill DataGridView using Entity Framework in VB.NET

It is quite easy to fill the DataGridView programatically in VB.NET.

There is no need to use the dataset, Data navigator and other such controls.

Here is an example/

There is a Model called Video already defined in my project and I need to display them in a datagrid view.

For the purpose of demonstrating I have kept it simple but we can use LINQ to build a complex query and then return that and display in the DataGridView.


 Private Sub frmVideoBrowse_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Me.DataGridView1.DataSource = GetVideos()

End Sub
Function GetVideos() As List(Of Video)
Dim db As New Entities
Dim resultlist As List(Of Video)
resultlist = db.Videos.ToList()
Return resultlist
End Function