• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

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

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.
1 Solution
Brian CroweCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now