Solved

hide column in datagrid

Posted on 2007-11-15
4
400 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now