We help IT Professionals succeed at work.

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

IT_Steve
IT_Steve asked
on
Medium Priority
257 Views
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.
Comment
Watch Question

Database Engineer
CERTIFIED EXPERT
Top Expert 2005
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.