Tag Archives: Visual Studio

How to fill up a ListView from database in VB.NET using a DataTable

You can easily use the following code to fill up your listview control from the data in a datatable using VB.NET


Supply the name of your listview and the datatable to this procedure and it will fill it up your list view.

If you wish to display the ongoing process then you can do that as well. Just create a label and then uncomment the following text in the procedure. Create a label and call it myStatusLabel.

‘ myStatusLabel.text = “Displaying Record ” & i + 1 & “/” & iRowCount



Sub FillListViewByTable(ByVal listView As ListView, ByVal dt As DataTable)
        Dim ii As Integer
        Dim iColCount As Integer = dt.Columns.Count
        Dim iRowCount As Integer = dt.Rows.Count
        For ii = 0 To iColCount – 1
            listView.Columns.Add(dt.Columns(ii).ColumnName, 250, HorizontalAlignment.Left)
        Dim i As Integer
        Dim x As Integer
        For i = 0 To iRowCount – 1  ‘ for each row in the table
            Dim lst As New ListViewItem
            lst.Text = dt.Rows(i).Item(0)
            lst.UseItemStyleForSubItems = True
            For x = 1 To iColCount – 1 ‘ for each column in the row of the table

           ‘    If you want to display the progress then you can do it here
           ‘ myStatusLabel.text = “Displaying Record ” & i + 1 & “/” & iRowCount
            lst = Nothing
    End Sub

How to restrict free Data Entry in ComboBox in Visual Studio

When you create a Combo Box in Visual Studio  , the default behaviour is that it will show the list and it will also allow the data entry. So a user can type something in instead of selecting the options listed in the Combo Box. This can cause issues as you might want the user to only select the valid options which are listed in your combo box.


Here is a simple way to achieve this behavior. Highlight the Combo Box on your form. The properties window will be show.

Change the Drop Down Style to  DropDownList as shown below.

Your combo box will not allow the users to type in any free text. they will have to select the options listed in your combo box.



Implement PagedList in VB.NET MVC3 or MVC4

How to use Paging using the PagedList

Once you have installed the PagedList package from NUGET




Add the following two imports at the top of the header

Imports PagedList
Imports PagedList.Mvc



Your Linq or SQL query should be sorted


Dim v = (From vid In db.qry_Videos Where vid.CatID = CatID Order By vid.OrderByID Select vid)

ViewBag.CurrentSort = v   ‘ This is most important you need to tell the view what your current sort order is

Return View(v)




In your view add the following imports at the top of the view

@imports PagedList
@imports PagedList.Mvc


Add the style sheet in your view as well. This will help you render your pager properly

<link href=”~/Content/PagedList.css” rel=”stylesheet” />


Wherever you want your pager to appear use the following

index” is the name of your view, if your view is named different then change it to your view

page”  – this is the variable which stores the current page number

“ViewBag.search – this is the ViewBag which you used in your controller

OnlyShowFivePagesAtATime  – this tells the pager how many buttons will be shown at one time ( this option shows

@Html.PagedListPager(DirectCast(ViewBag.CurrentSort, IPagedList), Function(page) Url.Action(“index“, New With {.page = page, .criteria = ViewBag.search}), PagedListRenderOptions.OnlyShowFivePagesAtATime)

How to add Nuget Packages

How to Add Packages using NUGET in Visual Studio

Step 1

In Visual Studio Go to Tools > Library Package Manager > Manage Nuget Packages for Solution.


How to add Nuget Packages
How to add Nuget Packages


Step 2

You would get the following screen, you can check the packages which you have already available in your solution, you can search for new packages and install them to your solution.

Remember:  These packages need to be downloaded , each time you create a new Visual Studio solution


Packages in NUGET
Packages in NUGET

How to fix : Ajax.BeginForm doing full postback instead of partial.

I realised that in my MVC5 project  in Visual Studio I could not get the Ajax.BeginForm to work properly. It will always do a full postback.


I was trying to complete a Video Rating Page, where there are buttons to rate a video and once the user presses one of the rating button, it should thank the user and display the new rating value. I wanted this to shown on the same page without reloading the page, So I considered using AJAX.BeginForm which will simply work fine.


In order to have this AJAX functionality you will have to download the AJAX from NUGET.


Step 1

Install the following two highlighted packages from NUGET. Click here to check how to load Packages from NUGET in Visual Studio




Step 2

Once you have installed the above two packages through NUGET then do the following.

Go to the _Layout file in your _shared  folder in the Views. ( Note that I am using VB.NET but the example will work for C# also.


_Layout in the Shared Folder
_Layout in the Shared Folder


Open the _Layout.vbhtml file and browse to the bottom.


You will see the following two lines.



Now add the following line after the above two lines.
<script src=”~/Scripts/jquery.unobtrusive-ajax.min.js”></script>


I made a mistake of adding this script at the top of my page and my AJAX calls refused to work.

Then I realised that the AJAX has to be loaded after loading the jquery. So I added it at the last.





Add the script at the exact position show.



Step 3

Run your application.

Your AJAX Calls should work fine.







Could not load file or assembly ‘Antlr3.Runtime’ Error in Visual Studio 2013 Express

While working on the Visual Studio 2013 Express, I was happily burning the midnight oil to produce a new application, the application was coming on nicely.

But When I started work next day, suddenly I started getting the following error message.

Could not load file or assembly 'Antlr3.Runtime' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))


After searching for long and trying different optionx the following solution did work for me and I was back in action. Hope you can benefit it from as well.

Step 1
Go to the file explorer and search for %Temp% (See the screen below)


Step 2
You would see lots of file in Temp folder. Delete them all.


Step 3

Run Visual Studio 2013 Express again and you would be able to work again on your project.