Click to See Complete Forum and Search --> : datagrid column
hussein2000
May 1st, 2006, 04:28 AM
hell friend
how to hide some column from datagrid
i have 6 col in datagrid and when i want to search it showed me all 6 col but incase i do not wwant to print all 6 col only i want three or 4 or 5
what to do ?
i put check box on the form for all col to hide the col for printing or it show 0000000 in the field of selected col so what to do here i mean which code i can use here to hide any col selected in the time of printing .
thanks
aniskhan
May 1st, 2006, 11:58 AM
consider that i have a datatable with 3 columns(rno,Name,Year)
now i don't want to show the first column "rno" ,to do this i use tablestyles in this way
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\attendence.mdb;Persist Security Info=False")
Dim adapter As New OleDbDataAdapter()
Dim sSQL As String = "SELECT * FROM student"
Dim dt As New DataTable("myStudent")
Dim cmd As New OleDbCommand(sSQL, conn)
'Fill the dataTable
adapter.SelectCommand = cmd
conn.Open()
adapter.Fill(dt)
conn.Close()
'declare tableStyle and dataGrid columnStyles
Dim myStyle As New DataGridTableStyle()
Dim Name As New DataGridTextBoxColumn()
Dim Year As New DataGridTextBoxColumn()
DataGrid1.BeginInit()
DataGrid1.DataSource = dt
'add myStyle to datagrid TableStyles
DataGrid1.TableStyles.AddRange(New DataGridTableStyle() {myStyle})
myStyle.DataGrid = DataGrid1
'add the 2 dataGridColumns to myStyle
myStyle.GridColumnStyles.AddRange(New DataGridColumnStyle() {Name, Year})
myStyle.MappingName = "myStudent"
'connect datagridColumns with the columns of the dataTable(myStudent)
Name.MappingName = "name"
Year.MappingName = "year"
DataGrid1.EndInit()
End Sub
jhammer
May 2nd, 2006, 06:06 AM
aniskhan is correct.
For more information about column styles:
How to use DataGridColumnStyles (http://j1hammer.blogspot.com/2005/10/how-to-use-datagridcolumnstyles.html)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.