Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Dear all,

 

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

 

Thanks

 

PlayKid

Posted

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.

Posted (edited)

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:

 

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

 

this.myDataGrid.Columns[0].Visible = False;

 

I'm not sure of the Windows version, but it's 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.

Edited by bri189a
Posted

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.

 

ClientDataSet1.Tables("Client").Columns("ClientNo").ColumnMapping = MappingType.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...