Link to home
Start Free TrialLog in
Avatar of lgropper
lgropper

asked on

Hiding columns in Datagrid

I have this code. Has zero effect on the column "style". Please help.

        Dim c As DataGridTextBoxColumn
        Dim ts As DataGridTableStyle

        Me.dgStyles.DataSource = MyStyleTable
        ts = New DataGridTableStyle
        ts.MappingName = "tstyle"

        c = New DataGridTextBoxColumn
        c.MappingName = "Style"
        c.Width = 0
        c.HeaderText = "Style"
        ts.GridColumnStyles.Add(c)
        Me.dgStyles.TableStyles.Add(ts)
       
        Me.dgStyles.RowHeadersVisible = True

        Me.dgStyles.ReadOnly = True
Avatar of mydasx
mydasx

is this for windows form or for asp.net?  Where are you calling this piece of code?
typically when i see no net effect when i am setting up a control, it means that either i forgot to call my method that sets up the control, or the control is being setup differently later in the execution.  Need more info to help.
Avatar of lgropper

ASKER

I am calling it from the form load.
Windows form
are you assigning your styles to the grid?

Put this at the end of your code
Me.DataGrid1.TableStyles.Add(ts)
Yes I have that exact line in the above code.
dgstyles is the name of grid i see.
ASKER CERTIFIED SOLUTION
Avatar of mydasx
mydasx

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah. I just don't get it. I have tried everything. I added the field names in manually (not with code) by draggin the element control onto the dataset and adding 8 column names. Could this have anything to do with it?
I got it working by fiddling around with the datatable instead.

ex.
MyStyleTable.PictureColumn.ColumnMapping = MappingType.Hidden

Thanks for your effort.