Possible to hide columns in the Datagrid?

PlayKid

Active member
Joined
Jun 25, 2005
Messages
38
Dear all,

Just wonder is it possible to hide any columns in the datagrid? I have read some books, but they didnt say anything about this issue, but is it possible.

Thanks

PlayKid
 
Yes, you need to set the appropriate width in the TableStyle to 0.

If you are allowing the DataGrid to create the TableStyle manually, then after you set the Datasource of the datagrid, do:

datagrid.TableStyles(0).GridColumnStyles(YourColumnIndex).Width = 0

This will make the width of the column 0, and therefore not visible.

If you are creating the tablestyle yourself, simply include the relevant columns in the tablestyle that you wish to display. Any other columsn in the datatable/dataset that are not named in your tablestyle will simply not appear.

B.
 
If your speaking of an ASP.NET datagrid, the easy way would be to:

In design mode click on the datagrid, and then open the properties page. For the column you want to hide, uncheck the Visible check box.

In code:

Code:
Me.myDataGrid.Columns(0).Visible = False

C#:
this.myDataGrid.Columns[0].Visible = False;

Im not sure of the Windows version, but its probably similiar. At no time should you have to use an integer to represent a visibility state in .NET - at the minimum there will be an enumeration.
 
Last edited by a moderator:
Thanks for both of your replies, but I have used another method, here is my code, if there is anyone would like to use as well.

[VB]
ClientDataSet1.Tables("Client").Columns("ClientNo").ColumnMapping = MappingType.
[/VB]
 
Back
Top