How to manipulate column in datagrid?

tommy_cs

Member
Joined
Jun 7, 2006
Messages
18
Programming Experience
3-5
Is it possoble to hide some of the columns in VB.NET application. I know it is easy to hide a column in ASP.NET, is there similar method provided in VB.NET?:(

Thanks in advance!:confused:
 
still have problem...

Thanks for your reply.

I have try them. it seems datagrid in vb.net window application don't support colums method.

I try to use TableStyles but it seems return null even the datagrid is filled with data.

maybe the only way is to use different select command and fill the datagrid everytime when I need hide a column..?

and I am so confuse that datagrid in web application and window application are so different!

I use VS.NET 2003, is it different from 2005?
Here is my code.


VB.NET:
Private strDbCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=abc.mdb"
Private cnDB As New OleDbConnection(strDbCon) ' connection to database 
Private daDB As OleDbDataAdapter
Private dsDB As New DataSet
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cnDB.Open()
daDB = New OleDbDataAdapter("select * from Data", cnDB)
daDB.Fill(dsDB)
dgHis.DataSource = dsDB.Tables(0)
Dim grid As New DataGrid
'-------------the following code i copy from [URL="http://www.vbdotnetheaven.com/UploadFile/prvn_131971/HideDataGridcolumnInVB11172005020153AM/HideDataGridcolumnInVB.aspx?ArticleID=daa8d4d5-7b0d-4265-9f8e-ed62aaabb58e"]http://www.vbdotnetheaven.com/UploadFile/prvn_131971/HideDataGridcolumnInVB11172005020153AM/HideDataGridcolumnInVB.aspx?ArticleID=daa8d4d5-7b0d-4265-9f8e-ed62aaabb58e[/URL]
'----------------
For Each dgt As DataGridTableStyle In dgHis.TableStyles
MsgBox(dgt.MappingName)
For Each dgc As DataGridColumnStyle In dgt.GridColumnStyles
dgc.Width = 0
Next dgc
Next dgt
 
End Sub
 
Last edited by a moderator:
The DataTable of your DataSet holds the DataColumns. You should be able to set the ColumnMapping of a DataColumn to MappingType.Hidden. I think it is correct that there are no TableStyles by default, even after you fill from DataAdapter, but you can apply one where you set the Width=0 to some column. See the second post of this thread for an example of applying DataGridTableStyle: http://www.vbdotnetforums.com/showthread.php?t=10679&highlight=tablestyles

Windows and Web developements are very different, that's true. VS2003/2005 with .Net 1/2 there are also some differences, in .Net 2.0 you got the DataGridView that is a lot better and easier than the DataGrid.
 
Back
Top