Question DataGridViewto only pull these columns

GMC

Member
Joined
May 6, 2011
Messages
12
Programming Experience
1-3
Hi Guys

Just wondering if someone could shed some light on this. I have a table with multilpe adaptors attached to it. I then have a DataGridViewthat im pushing the data to. I need to assign only certain columns to my DataGridViewfor example column 1, 3, 5 and 9. Im not to sure how to tell the DataGridViewto only pull these columns from my table. Any help appreicated.

Gav
 
Add the columns you want to the grid in the designer, setting their DataPropertyName properties to the names of the source columns you want them to bind to. Before you set the DataSource in code, set AutoGenerateColumns to False.
 
Add the columns you want to the grid in the designer, setting their DataPropertyName properties to the names of the source columns you want them to bind to. Before you set the DataSource in code, set AutoGenerateColumns to False.

The datatable ive created is created programmatically so doesnt give an option to set inside the designer window. The datagrid is going to hold different options aswell depending on the search selection made so i need a way of assigning this via the code if anyone knows that this is possible.
 
You can still add the columns in designer and set DataPropertyName as mentioned. Assigning a data source with these column names will not have duplicate columns autogenerated, but if the data source has more columns you have to hide these afterwards, or just set AutoGenerateColumns to False. You can also only select the columns you want to show in query, though is it common to include but hide id columns. Access a column by its name or index in the grids Columns property and set the columns Visible property to False to hide it.
 

Latest posts

Back
Top