Hide Columns in a datagrid

G

Guest

Hi there,

Can anyone tell me how to hide a column in a datagrid??.. I have tried to
assign a DataGridTableStyle to the datagrid, but it does not seems to work??
It shows all rows instead of the one speciffied?? see below..

Thanks

Dim ts As New DataGridTableStyle()
ts.MappingName = "Orders"

Dim colOrder As New DataGridTextBoxColumn()
With colOrder
.MappingName = "OrderID"
.HeaderText = "CustomerOrderID"
.Width = 100
.ReadOnly = True
End With


ts.GridColumnStyles.Add(colOrder)

DataGrid1.TableStyles.Add(ts)
ts = Nothing
colOrder = Nothing

DataGrid1.DataSource = CustomerOrdersDataSet.Tables(0)
 
C

Chris

Henrik said:
Hi there,

Can anyone tell me how to hide a column in a datagrid??.. I have tried to
assign a DataGridTableStyle to the datagrid, but it does not seems to work??
It shows all rows instead of the one speciffied?? see below..

Thanks

Dim ts As New DataGridTableStyle()
ts.MappingName = "Orders"

Dim colOrder As New DataGridTextBoxColumn()
With colOrder
.MappingName = "OrderID"
.HeaderText = "CustomerOrderID"
.Width = 100
.ReadOnly = True
End With


ts.GridColumnStyles.Add(colOrder)

DataGrid1.TableStyles.Add(ts)
ts = Nothing
colOrder = Nothing

DataGrid1.DataSource = CustomerOrdersDataSet.Tables(0)

Try this.... You table has to be named the same as the
DataGridTableStyle mappingname.

Dim ts As New DataGridTableStyle()
ts.MappingName = "Orders"

Dim colOrder As New DataGridTextBoxColumn()
With colOrder
.MappingName = "OrderID"
.HeaderText = "CustomerOrderID"
.Width = 100
.ReadOnly = True
End With


ts.GridColumnStyles.Add(colOrder)

DataGrid1.TableStyles.Add(ts)
ts = Nothing
colOrder = Nothing

Dim DT as DataTable = CustomerOrdersDataSet.Tables(0)
DT.TableName = "Orders"
DataGrid1.DataSource =
 
G

Guest

Hi Cor,,

Thanks :) have been there a couple of times, but could't locate it?

-But im developing in mdi-forms, a get's an error on the parent-form, when i
creates the child form? .. an out of memory exception + Error creating
window handle.

Im creating the new form by:
Dim NewMDIChild As New frmOrders()
NewMDIChild.MdiParent = Me
NewMDIChild.Show()

-But chris has soveld the problem for me :) -YES
But it seems kind of slow??

But thank you for your time.
 
C

Cor Ligthert [MVP]

Henrik,

I had seen the sample of Chris before I showed the link. The solution I
showed was withouth a style, however basicly it is only this.

\\\
dt.Columns("USA").ColumnMapping = MappingType.Hidden
///

Can you tell us why you could not reach our website (the error you got).

We had a very little program error yesterday for about 2 hours in very
special occassions however for the rest it should be online already for a
long time.

Cor
 
G

Guest

Hi Cor,,

ok thanks,, I will try that later to night :blush:)...

Regarding the site.... I did't get an error on your website... I just
haven't been lucky to find the exampel you linked to?... So the site works
just fine, and have been add'ed to my favorites :blush:)

Again thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top