Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridView, DataSource, and Unwanted Columns

Status
Not open for further replies.

gharabed

Programmer
Sep 7, 2001
251
US
I was wondering if there is an easier way to hide unwanted columns in a dataGridView when setting the DGVs datasource to a dataTable. Basically I run a query against a database populating a data set (and hence a dataTable). I am setting the dataGridView's data source to the dataTable in the DataSet. However, I only want to display some of the columns. I've defined all of the columns and their dataProperty in the defined dataGridView. However, when I set the DataSource to the dataTable I've loaded, I see all of the columns. Right, now I am having to hide all of the unwanted columns via the "Columns.Visible" property to false. Kind of a pain since I know which columns I want displayed. Is there a way to tell the DGV to only display the column that are already defined in the DGV and not to display any other columns that may be added as a result of loading the DataTable? Hopefully this makes sense. I'll give an example...

The dataGridView I've defined say has 3 columns (A, B, and C). The dataTable I load has columns A, B, C, D, and E. When I set the dataSource to the dataTable, all of the queried columns appear in the dataGridView (A-E). Do I have to manually set the visible property of D and E to False or is there a way to tell the DGV to only display the defined columns (A-C)?

Thanks
Greg
 
You can design your columns in design time before you bind your grid, and make sure your grid has AutoGenerateColumns equal to False.
 
Hmmm...close. I want the columns generated as I want access to the values in the cells in the dataGridView...I just don't want them showing. Guess I do have to manually hide them.
 
Take a look @ thread796-1579979.

You can hide your columns during programming, or setup logical operators to hide them.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top