Remove Column from Data Grid Views in VB.NET

 DataGrid-Example-Vb.Net.gif 


Objective:

 

To remove the ever so annoying column that is added by default to the front of every row in a data grid view object in VB.NET.

 

Problem:

 

After searching for a solution to this rather easy problem, I decided that it would be best to post this online for others to see and benefit from.  In VB.NET when you use a data grid view object and populate it with data, the data grid view by default sets a column in front of every row so that you know which row you are editing or have selected cells.  Getting this column to disappear is rather simple.

 

The Fix:

 

There are two ways to fix this issue:

 

Fix # 1: 

 

After selecting the data grid view object, go to the properties for the data grid view and set the property "RowHeadersVisible" to False.

 

Fix # 2 (programmatically): 

 

Where dgv is the name of your data grid view object, insert this into your code when you want to hide this column.

 

// dgv.RowHeadersVisible = False

 

 

Conclusion:

 

While this may seem trivial, some users do not want to see this column.  If you ever run into this issue, now you have the tools necessary to tackle this simple issue without going through many hoops to perform the same action.

 

Happy Coding!


Similar Articles