How to display in a DataGrid only the columns of a dataSet that contain values?

Posted on 2006-03-27
Last Modified: 2010-04-23
Say I have a dataSet with 5 columns, denoted by ID_Code, Product_A, Product_B, Product_C, Product_D. Sometimes
the dataSet may only contain values for Product_A, Product_B, and Product_D (or other such combinations). There
will always be values for ID_Code. How do I set up my dataGrid to display only the columns containing values? For
this example, how do I make it appear as the following in my dataGrid? Bear in mind my next dataSet may contain
all the columns or perhaps any combination of Product columns.

ID_Code    PRoduct_A    Product_B    ProductD

Please provide code example. I am using VB.Net and Access database. Thank you for your assistance.
Question by:IT_Steve
    1 Comment
    LVL 34

    Accepted Solution

    you would have to loop through your datasource.  If no value is found for all records for a given column then set the width of its related datagridcolumnstyle = 0

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now