can datagrid column hidden in vb.net ?


L

Localbar

hi all,

If I have a datagrid, actually has 5 column. but I would like in run
time hidden last column.
The reason is the form also have combobox for filter datagrid row. my
problem is that I don't want the filter key show in datagrid. so that's why
I would like to hidden it...any idea..

Thanks
 
Ad

Advertisements

C

ClayB

Is this a Windows Forms DataGrid? If so, you can set the column width
to zero to hide a column provided you have a non-Nothing tablestyle.
Here is some code snippets.

'.... make sure your DataGrid is using a tablestyle
dataGrid1.DataSource = _dataSet.Tables("customers")
Dim dgts As New DataGridTableStyle()
dgts.MappingName = "customers"
dataGrid1.TableStyles.Add(dgts)

'......

'method to set a column with by colnumber
Public Sub SetColWidth(tableStyle As DataGridTableStyle, colNum As
Integer, width As Integer)
Try
tableStyle.GridColumnStyles(colNum).Width = width
tableStyle.DataGrid.Refresh()
Catch 'empty catch .. do nothing
End Try
End Sub 'SetColWidth

'....


' here is how you might call this method
Private Sub button1_Click(sender As Object, e As System.EventArgs)
Dim tableStyle As DataGridTableStyle =
dataGrid1.TableStyles("customers")
SetColWidth(tableStyle, 1, 0) 'set width to zero
End Sub 'button1_Click

===============
Clay Burch
Syncfusion, Inc.
 
W

Wayne Pedersen

In the designer (or via code) you can toggle the columns Visible
property off.

HTH,

Wayne P.
 
Ad

Advertisements


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