Hide a column in the .NET Winforms Datagrid

There are several ways to do this. You can create a custom DataGridTableStyle and add GridColumnStyles for each column in the grid except the column(s) to hide (see my How do I format columns in a datagrid page).

You can create a GridColumnStyle for the column to hide and set its Width to zero (see my Format columns in a datagrid page).

You can also use your DataSet's ColumnMapping property to hide a column.

    Imports System.Data.OleDb
    '
    ' Retrieve "Customer" data from database.  	
    '
    Dim strConnection = "Provider=..."  	
    Dim strSQL = "SELECT * FROM Customers"  	
    Dim conn As New OleDbConnection(strConnection)  	
    Dim DA As New OleDbDataAdapter(strSQL,conn)  	
    Dim DS As New DataSet()  
    DA.Fill(DS, "Customers")  
    '
    ' Hide the column.
    '
    DS.Tables("Customers").Columns("LastName").ColumnMapping = MappingType.Hidden  
    DataGrid.DataSource = DS.Tables("Customers")




About TheScarms
About TheScarms


Sample code
version info

If you use this code, please mention "www.TheScarms.com"

Email this page


© Copyright 2024 TheScarms
Goto top of page