Click to See Complete Forum and Search --> : datagrid - hide columns
escape0
Dec 4th, 2002, 05:56 AM
hi!
Is it possible to hide one ore more columns of a datagrid?
I have a dataset which contains all fields of a sql-server-table but i only want to show a few of them.
Of course i could create a dataset which contains only the necessary fields but in this case i have to read the data from the sql-server once again.
thanks
Robert
CoMMiE
Dec 4th, 2002, 07:44 AM
Yes you can
just set the datagridtextboxcolumn.width properties of the mapping column to zero
escape0
Dec 4th, 2002, 08:41 AM
thanks...
here's my coding... the method objBenutzer.getAllBenutzer() generates a dataset with 15 fields but only the 3 mapped fields are shown in the datagrid.
Dim objBenutzer As New cls_ety_benutzer()
objBenutzer.getAllBenutzer()
Dim dgTableStyle = New DataGridTableStyle()
Dim dgTextBoxColumn1 = New DataGridTextBoxColumn()
Dim dgTextBoxColumn2 = New DataGridTextBoxColumn()
Dim dgTextBoxColumn3 = New DataGridTextBoxColumn()
dgTableStyle.DataGrid = Me.dgBenutzer
dgTableStyle.GridColumnStyles.AddRange(New DataGridColumnStyle() {dgTextBoxColumn1, dgTextBoxColumn2, dgTextBoxColumn3})
dgTableStyle.HeaderForeColor = System.Drawing.SystemColors.ControlText
dgTableStyle.MappingName = "tbl_cu_benutzer"
dgTableStyle.ReadOnly = True
dgTextBoxColumn1.Format = ""
dgTextBoxColumn1.FormatInfo = Nothing
dgTextBoxColumn1.MappingName = "Benutzername"
dgTextBoxColumn1.Width = 75
dgTextBoxColumn2.Format = ""
dgTextBoxColumn2.FormatInfo = Nothing
dgTextBoxColumn2.MappingName = "Vorname"
dgTextBoxColumn2.Width = 75
dgTextBoxColumn3.Format = ""
dgTextBoxColumn3.FormatInfo = Nothing
dgTextBoxColumn3.MappingName = "Nachname"
dgTextBoxColumn3.Width = 75
' Tablestyle dem Datagrid zuweisen
dgBenutzer.TableStyles.Add(dgTableStyle)
dgBenutzer.SetDataBinding(objBenutzer.DataSet, "tbl_cu_benutzer")
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.