DataGridView hiding rows and columns in VB.NET

The DataGridView control in Windows Forms serves as a versatile and customizable table for presenting data. Its extensive set of properties, methods, and events empowers developers to fine-tune its visual appearance and functionality. As data display in a tabular format is a common requirement, the DataGridView control provides a comprehensive solution for this purpose.

In the following VB.NET source code, we demonstrate how to manually create columns and rows within a DataGridView control while also hiding the second column and second row:

DataGridView1.Rows(Index).Visible = False

DataGridView1.Columns(Index).Visible = False

Full Source VB.NET
Imports System.Data.SqlClient Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DataGridView1.ColumnCount = 3 DataGridView1.Columns(0).Name = "Product ID" DataGridView1.Columns(1).Name = "Product Name" DataGridView1.Columns(2).Name = "Product_Price" Dim row As String() = New String() {"1", "Product 1", "1000"} DataGridView1.Rows.Add(row) row = New String() {"2", "Product 2", "2000"} DataGridView1.Rows.Add(row) row = New String() {"3", "Product 3", "3000"} DataGridView1.Rows.Add(row) row = New String() {"4", "Product 4", "4000"} DataGridView1.Rows.Add(row) DataGridView1.Rows(1).Visible = False End Sub End Class

By utilizing this code snippet, you can create a DataGridView control and customize its structure by manually adding columns and rows. Additionally, you have the flexibility to hide specific columns or rows based on your requirements, granting you full control over the appearance and content displayed within the DataGridView.