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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid questions

Status
Not open for further replies.

Axoliien

Programmer
Aug 19, 2003
166
US
I am just starting into ADO.Net using Visual Basic .Net in a Windows application environment. I have been told that the DataGrid gives advantages over list boxes, etc however I can't seem to see why this is. For one thing, when I bind a DataTable to a DataGrid, I can't seem to hide any columns. I have looked over code examples and none seem to work. Also, when I bind a DataSet to a DataGrid, I receive a tree structure from which to choose tables, even if there is only one table. So far, the DataGrid just seems to be a complex tree structure view of table data, and that is not very helpful.

The real purpose of using the DataSet is to store tabular data and filter, relation, etc at run-time without requerying the database every time. In this way, I will end up getting the data I want as a view or single table would look, and want to hide certain fields depending on data retrieved.

First, would someone explain why you would use a DataGrid, and second would someone tell me if it is possible to hide columns in a DataGrid?

Thanks!
 
You can hide columns by creating TableStyles. If you choose not not "make" a column in your TableStyle, then it won't show up on the grid. You can also change the column name text, and the format of the data. You are receiving that drill-down chooser because you are not setting the DataMember of your DataGrid. If you just want to DISPLAY data, I quite often choose a ListView instead of a DataGrid. If you need to allow the user to modify and add data, then you need the DataGrid.

As a summary, this is how it works:
1. You make a TableStyle for your DataGrid.
2. The TableStyle will have a MappingName equal to your Table Name.
3. Each TableStyle can have ColumnStyles. This is where you tell it what columns you want to display and in what format.
4. When you bind your DataGrid to your particular table, it will use the formatting of your TableStyle that is defined for the table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top