473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

can datagrid column hidden in vb.net ?

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
Apr 12 '07 #1
4 6647
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.

Apr 12 '07 #2
In the designer (or via code) you can toggle the columns Visible
property off.

HTH,

Wayne P.
ClayB wrote:
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.
Apr 12 '07 #3
now is ok...
Thanks Clay

"ClayB" <cl***@syncfusion.com???
news:11**********************@p77g2000hsh.googlegr oups.com ???...
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.

Apr 13 '07 #4
Thanks
I try it also ok..
"Wayne Pedersen" <wa************@no.spam.teksol.com???
news:%2****************@TK2MSFTNGP02.phx.gbl ???...
In the designer (or via code) you can toggle the columns Visible
property off.

HTH,

Wayne P.
ClayB wrote:
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.

Apr 13 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Derek | last post by:
Another DGrid question... I can not access the values of a cell in a datagrid unless I make them visible. I do not want these fields displayed. I only want to use the values to run a stored...
4
by: chris | last post by:
Hello group, The datagrid I use needs to add a hidden column on demand (only on certain conditions). The sequence of events would be as below: 1) get the dataset(ds) and bind the datagrid(dg) with...
3
by: Brad | last post by:
I'm working with a DataGrid in C#, and the user needs to be able add and remove columns from the DataGrid on the fly, without opening and closing the form. The scenario is this. I have a setup...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Ryan Riddell | last post by:
I am using the DataGrid control from 4guys (http://aspnet.4guysfromrolla.com/demos/RowHighlighter.aspx). I want to display 2 columns and allow editing. The only column I want the user to be able to...
2
by: Mortar | last post by:
i have a datagrid with 2 columns. the 1st column contains an id which will be used by the database for the selected checkbox records. the 2nd column is a template column containing a server...
2
by: Not Me | last post by:
Hi, In a datagrid's itemcommand method, I can use DataGridCommandEventArgs/item/cells/text to bring up a specific field from a row that was accessed. However, I wish to lookup data from that...
5
by: Rich | last post by:
I have a datagrid that uses a dataview object for its datasource. The dataview contains a unique row identifier column. I don't want to display this column in the datagrid. I need the unique row...
2
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3...
6
by: Doug Bell | last post by:
Hi I have a DataGrid with some hidden columns and also some read Only and some ComboBox Columns. Sandard Tabbing through the Datagrid sees the focus go to the hidden columns requiring further...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.