Solved

hide column in datagrid

Posted on 2007-11-15
4
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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