By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,912 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

Hide Columns in Datagrid

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.