Solved

hide column in datagrid

Posted on 2007-11-15
4
406 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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