Solved

hide column in datagrid

Posted on 2007-11-15
4
410 Views
Last Modified: 2013-11-26
I have this code behind on pageload :

       Dim dss As New DataSet
     
        dss = myProfile.getsubjects(categoryid)

        datagrid1.DataSource = dss.Tables(0)

my dss has 5 columns but i want to show only 2 of them on datagrid. I don't  want to cut the 3 of them as i use all column info.
Just want to show only the 2 columns.

How i change the column name to be diferent from the name of the sql tables i have on my database?

Thanx
0
Comment
Question by:Inteliscape
  • 2
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 20288219
Q1. How do I hide a column in a DataGrid or DataTable?

Ans. DataGrid.Columns(index).Visible = False

See also: Mapping type?

Set DataColumn.MappingType as MappingType.Hidden

ONE MORE VERSION: GRID ONLY:

The grid part of a DataGrid is represented by a table. The TableStyles property provides to this table. TableStyles property returns an object of type DataGridTableStyle, which provides access to all columns in the form of DataGridColumnStyles collection. The GridColumnStyles property of DataGridTableStyle returns it, from where you can get one DataGridColumnStyle. The DataGridColumnStyle represents the style of a column and you need to set Width property of DataGridColumnStyle to 0.

Something like this:

For Each dgt As DataGridTableStyle In myDataGrid.TableStyles
Console.WriteLine(dgt.MappingName)
For Each dgc As DataGridColumnStyle In dgt.GridColumnStyles
dgc.Width = 0
Next dgc
Next dgt

Source: http://www.vbdotnetheaven.com/Uploadfile/prvn_131971/HideDataGridcolumnInVB11172005020153AM/HideDataGridcolumnInVB.aspx?ArticleID=daa8d4d5-7b0d-4265-9f8e-ed62aaabb58e
0
 
LVL 2

Author Comment

by:Inteliscape
ID: 20288480
DataGrid.Columns(index).Visible = False

When i write the above i get this message :
'Columns' is not a member of 'System.Windows.Forms.Datagrid'
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 50 total points
ID: 20288523
Hide a column in the .NET Winforms Datagrid
There are several ways to do this. You can create a custom DataGridTableStyle and add GridColumnStyles for each column in the grid except the column(s) to hide (see my How do I format columns in a datagrid page).

You can create a GridColumnStyle for the column to hide and set its Width to zero (see my Format columns in a datagrid page).

You can also use your DataSet's ColumnMapping property to hide a column.

Source: http://www.thescarms.com/dotnet/HideColumn.aspx
0
 
LVL 2

Author Comment

by:Inteliscape
ID: 20288577
sorry for not mentioning before but i am working on a windows form and not a web one. The code you've sent me before works well in the case of a web application but not a windows one.
Can you please help me on the environment i am working at?
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question