Search Amazon:

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")

Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

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

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms