473,378 Members | 1,623 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,378 software developers and data experts.

Hide Columns in Datagrid

J
Ok, they have changed a lot of stuff in VB.net. How in the world do you hide a column on the Datagrid?
--
Jason

Nov 21 '05 #1
5 7789
Hi,

Add a tablestyle to your datagrid.

http://msdn.microsoft.com/library/de...stdatagrid.asp

Ken
--------------------
"J" <fo***********@nowhere.com> wrote in message
news:O4*************@TK2MSFTNGP11.phx.gbl...
Ok, they have changed a lot of stuff in VB.net. How in the world do you hide
a column on the Datagrid?
--
Jason
Nov 21 '05 #2
J
I have been trying that but am having issues: here is the code I have been
trying:

I have been experimenting with a bunch of different methods but I cannot get
the setbinding to work.

Any ideas?

Private Sub Query_Grid()

Dim strSQL As String

strSQL = "SELECT tblLogged.log_ID, format(tblLogged.time_start,'HH:MM') AS
Start, format(tblLogged.time_end,'HH:MM') AS [End], tblLogged.act_cat AS
Category, tblLogged.act_desc AS Description, tblLogged.user_name,
tblLogged.act_date"

strSQL = strSQL & " FROM(tblLogged)"

strSQL = strSQL & " WHERE(((tblLogged.user_name) = '" & g_User & "') And
((tblLogged.act_date) = #" & String.Format("{0:MM\/dd\/yyyy}",
Me.dtDate_Val.Value) & "#))"

strSQL = strSQL & " ORDER BY tblLogged.time_start, tblLogged.time_end;"

Me.DataGrid1.DataSource = Nothing

Dim AppPath As String = g_ODBC

Dim cn As New OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0; Data Source
= " + AppPath)

Dim cmd As New OleDbCommand(strSQL, cn)

Dim da As New OleDbDataAdapter(cmd)

Dim ds As New DataSet

' Dim customersTable As DataTable = New DataTable("Customers")

'' Insert code to set source to populate DataSet.

'' Set DataSource and DataMember with SetDataBinding method.

'Dim member As String

'' The name of a DataTable is Customers.

'member = "Customers"

'DataGrid1.SetDataBinding(myDataSet, member)

da.Fill(ds)

Me.DataGrid1.DataSource = ds.Tables(0)

DataGrid1.SetDataBinding(ds, "tblLogged")

Me.DataGrid1.Refresh()

Dim member As String

' The name of a DataTable is Customers.

member = "Customers"

'Me.DataGrid1.FirstVisibleColumn(1)

'hide the first column

'log_ID

'ts.MappingName = DataGrid1.DataMember

'ts.MappingName = DataGrid1.DataSource

' Add it to the datagrid's TableStyles collection

'DataGrid1.TableStyles.Add(ts)

DataGrid1.TableStyles(0).GridColumnStyles(0).Width = 0

'' Set the DataGridTableStyle.MappingName property

'' to the table in the data source to map to.

'ts.MappingName = DataGrid1.DataMember

'' Add it to the datagrid's TableStyles collection

'DataGrid1.TableStyles.Add(ts)

'' Hide the first column (index 0)

'DataGrid1.TableStyles(0).GridColumnStyles(0).Widt h = 0



Me.DataGrid1.Refresh()

cn.Close()

End Sub
--
Jason J. Hansen
ja***@cabhansen.com
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OD**************@TK2MSFTNGP11.phx.gbl...
Hi,

Add a tablestyle to your datagrid.

http://msdn.microsoft.com/library/de...stdatagrid.asp
Ken
--------------------
"J" <fo***********@nowhere.com> wrote in message
news:O4*************@TK2MSFTNGP11.phx.gbl...
Ok, they have changed a lot of stuff in VB.net. How in the world do you hide a column on the Datagrid?
--
Jason

Nov 21 '05 #3
J
OK, so i figured it out myself (kindof, thanks for the head start Ken).

If anybody wants the code to hide the column read the following:

'under forms declarations add this

Inherits System.Windows.Forms.Form

Private Sub Query_Grid()

Dim strSQL As String

strSQL = "SELECT tblLogged.log_ID, format(tblLogged.time_start,'HH:MM') AS Start, format(tblLogged.time_end,'HH:MM') AS [End], tblLogged.act_cat AS Category, tblLogged.act_desc AS Description, tblLogged.user_name, tblLogged.act_date"

strSQL = strSQL & " FROM(tblLogged)"

strSQL = strSQL & " WHERE(((tblLogged.user_name) = '" & g_User & "') And ((tblLogged.act_date) = #" & String.Format("{0:MM\/dd\/yyyy}", Me.dtDate_Val.Value) & "#))"

strSQL = strSQL & " ORDER BY tblLogged.time_start, tblLogged.time_end;"

Dim AppPath As String = g_ODBC

Dim cn As New OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0; Data Source = " + AppPath)

Dim cmd As New OleDbCommand(strSQL, cn)

Dim da As New OleDbDataAdapter(cmd)

Dim ds As New DataSet

da.Fill(ds)

DataGrid1.DataSource = Nothing

DataGrid1.DataSource = ds.Tables(0)

DataGrid1.SetDataBinding(ds, ds.Tables(0).ToString)

ts.MappingName = DataGrid1.DataMember

' Add it to the datagrid's TableStyles collection

DataGrid1.TableStyles.Add(ts)

DataGrid1.TableStyles(0).GridColumnStyles(0).Width = 0

'hide the last 2 columns

DataGrid1.TableStyles(0).GridColumnStyles(5).Width = 0

DataGrid1.TableStyles(0).GridColumnStyles(6).Width = 0

Me.DataGrid1.Refresh()

cn.Close()

End Sub


--
Jason J. Hansen
ja***@cabhansen.com
"J" <fo***********@nowhere.com> wrote in message news:O4*************@TK2MSFTNGP11.phx.gbl...
Ok, they have changed a lot of stuff in VB.net. How in the world do you hide a column on the Datagrid?
--
Jason

Nov 21 '05 #4
Save your fingers:

ds.Tables("dt").Columns("UnwantedColumn").ColumnMa pping = MappingType.Hidden
DataGrid1.DataSource = ds.Tables("dt")
"J" <fo***********@nowhere.com> wrote in message
news:eU*************@TK2MSFTNGP11.phx.gbl...
OK, so i figured it out myself (kindof, thanks for the head start Ken).
If anybody wants the code to hide the column read the following:

'under forms declarations add this
Inherits System.Windows.Forms.Form

Private Sub Query_Grid()
Dim strSQL As String
strSQL = "SELECT tblLogged.log_ID, format(tblLogged.time_start,'HH:MM') AS
Start, format(tblLogged.time_end,'HH:MM') AS [End], tblLogged.act_cat AS
Category, tblLogged.act_desc AS Description, tblLogged.user_name,
tblLogged.act_date"
strSQL = strSQL & " FROM(tblLogged)"
strSQL = strSQL & " WHERE(((tblLogged.user_name) = '" & g_User & "') And
((tblLogged.act_date) = #" & String.Format("{0:MM\/dd\/yyyy}",
Me.dtDate_Val.Value) & "#))"
strSQL = strSQL & " ORDER BY tblLogged.time_start, tblLogged.time_end;"

Dim AppPath As String = g_ODBC
Dim cn As New OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0; Data Source
= " + AppPath)
Dim cmd As New OleDbCommand(strSQL, cn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
DataGrid1.DataSource = Nothing
DataGrid1.DataSource = ds.Tables(0)
DataGrid1.SetDataBinding(ds, ds.Tables(0).ToString)
ts.MappingName = DataGrid1.DataMember
' Add it to the datagrid's TableStyles collection
DataGrid1.TableStyles.Add(ts)
DataGrid1.TableStyles(0).GridColumnStyles(0).Width = 0
'hide the last 2 columns
DataGrid1.TableStyles(0).GridColumnStyles(5).Width = 0
DataGrid1.TableStyles(0).GridColumnStyles(6).Width = 0
Me.DataGrid1.Refresh()
cn.Close()
End Sub
--
Jason J. Hansen
ja***@cabhansen.com
"J" <fo***********@nowhere.com> wrote in message
news:O4*************@TK2MSFTNGP11.phx.gbl...
Ok, they have changed a lot of stuff in VB.net. How in the world do you hide
a column on the Datagrid?
--
Jason
Nov 21 '05 #5
J
Sweet! Thanks!
--
Jason J. Hansen
ja***@cabhansen.com
"Earl" <br******@newsgroups.nospam> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
Save your fingers:

ds.Tables("dt").Columns("UnwantedColumn").ColumnMa pping = MappingType.Hidden DataGrid1.DataSource = ds.Tables("dt")
"J" <fo***********@nowhere.com> wrote in message
news:eU*************@TK2MSFTNGP11.phx.gbl...
OK, so i figured it out myself (kindof, thanks for the head start Ken).
If anybody wants the code to hide the column read the following:

'under forms declarations add this
Inherits System.Windows.Forms.Form

Private Sub Query_Grid()
Dim strSQL As String
strSQL = "SELECT tblLogged.log_ID, format(tblLogged.time_start,'HH:MM') AS
Start, format(tblLogged.time_end,'HH:MM') AS [End], tblLogged.act_cat AS
Category, tblLogged.act_desc AS Description, tblLogged.user_name,
tblLogged.act_date"
strSQL = strSQL & " FROM(tblLogged)"
strSQL = strSQL & " WHERE(((tblLogged.user_name) = '" & g_User & "') And
((tblLogged.act_date) = #" & String.Format("{0:MM\/dd\/yyyy}",
Me.dtDate_Val.Value) & "#))"
strSQL = strSQL & " ORDER BY tblLogged.time_start, tblLogged.time_end;"

Dim AppPath As String = g_ODBC
Dim cn As New OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0; Data Source = " + AppPath)
Dim cmd As New OleDbCommand(strSQL, cn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
DataGrid1.DataSource = Nothing
DataGrid1.DataSource = ds.Tables(0)
DataGrid1.SetDataBinding(ds, ds.Tables(0).ToString)
ts.MappingName = DataGrid1.DataMember
' Add it to the datagrid's TableStyles collection
DataGrid1.TableStyles.Add(ts)
DataGrid1.TableStyles(0).GridColumnStyles(0).Width = 0
'hide the last 2 columns
DataGrid1.TableStyles(0).GridColumnStyles(5).Width = 0
DataGrid1.TableStyles(0).GridColumnStyles(6).Width = 0
Me.DataGrid1.Refresh()
cn.Close()
End Sub
--
Jason J. Hansen
ja***@cabhansen.com
"J" <fo***********@nowhere.com> wrote in message
news:O4*************@TK2MSFTNGP11.phx.gbl...
Ok, they have changed a lot of stuff in VB.net. How in the world do you hide a column on the Datagrid?
--
Jason

Nov 21 '05 #6

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

Similar topics

2
by: Andrew Chen | last post by:
How do I hide any particular DataGrid Cell from visible, or any DataColumn for the matter?
6
by: Das | last post by:
Hi everyone, I'm using datagrid control to display the data. I want to hide column to be displayed into the data grid. I'm using the code as given below: Method given below is used to bind the...
4
by: Tim | last post by:
Hi, I am trying to hide the datagrid row header (the left most column that has the 'select' triangle in it which moves with the selected row). It seems to be fairly simple;...
1
by: J Gao | last post by:
Hi All, I am using Data binding with DataGrid. I need to hide column in the grid using DataGrid1.Columns(1).Visible = False But I get the following error message Description: An unhandled...
2
by: Thanh Nu | last post by:
Hi, I would like to hide a column in a web datagrid (with create columns automatically at runtime checked), and I cannot refer to the columns collection like this: DataGrid1.Columns(0).Visible...
8
by: Hanson | last post by:
I have a datagrid control in an aspx page. The datagrid columns will be dynamically generated according to the pre-page's search condition, I want to hide some columns in the datagrid. is that...
3
by: sivaraman.S | last post by:
Hi friends, How to hide a column in datagrid. regards, Sivaraman.S
1
by: nuhura01 | last post by:
Hi all.. I have a datagrid in my system and I preview the datagrid in other html page. Below are the code that I'm using: Dim oStringWriter As System.IO.StringWriter = New...
9
by: moondaddy | last post by:
using c# 3.5 I have list of business objects which I will use in lists for databinding and I want to hide some of the fields so they don't show up in the list control. some of my list will be:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.