none
How to show/hide column in GridView

    Question

  • Hi everybody,

    Please help me show/hide column in GridView of Avalon. Datagridview of window form 2.0 has visible property in order to show/hide columns.

    Every body solved my issue, please let me knows.

    Thanks.

    Steven

    Wednesday, March 01, 2006 9:23 AM

Answers

  • To hide a column just set the width to 0.  To show it again set the width to auto.
    Wednesday, March 01, 2006 4:08 PM
    Moderator
  • That's for ASP Gridviews. However, it's good that we could revisit this matter. I think that setting Visibility to collapsed should do what the original poster wants.
    Friday, December 15, 2006 7:05 PM
    Moderator

All replies

  • To hide a column just set the width to 0.  To show it again set the width to auto.
    Wednesday, March 01, 2006 4:08 PM
    Moderator
  • Hi Michael

    I set width property = 0.However, I still resize this column when I move mouse on header column.

    Do you have another solution ?

    Thanks

    Steven

    Thursday, March 02, 2006 2:16 AM
  • How about using add/remove column since GridView is just a "view" of tabular data. Is that ok for your scenario?
    • Proposed as answer by Edgar S Sunday, August 07, 2011 10:05 AM
    • Unproposed as answer by Edgar S Sunday, August 07, 2011 10:05 AM
    Friday, March 03, 2006 6:41 AM
  • Sorry, that is not my scenario, You can take a look DataGridView of Window Form 2.0. when I set DataGridViewColumn.Visible = False, this column is hided, and then DataGridViewColumn.Visible = True this column is showed again.

    So far, is my scenario is clear ?

    Thanks for your help, I'm looking forward to hearing from you.

    Steven

    Thursday, March 09, 2006 1:56 AM
  • Currently GridView doesn't provide such a property for column. My point is, in most cases, you can use Add/Insert/Remove method in GridViewColumnCollection to have the same effect of show/hide. 

    Thursday, March 09, 2006 2:48 AM
  • use this
    GridView1.Columns[0].Visible = false;
    Wednesday, March 22, 2006 9:48 PM
  • the problem that i use an object data source that's why i must use autogeneratecolumn.
    and when i use it i can't use gridview.colomns[0] because the gridview don't see the colomn because of autogeneratecolumn. please help  me
    thank you.
    Wednesday, March 29, 2006 8:03 PM
  • Using the latest CTP trying to set the visibility of a column gives the following compilation error:

    Error 10 'System.Windows.Controls.GridViewColumn' does not contain a definition for 'Visible'

    So is changing the width the only way to accomplish this?  I'm imagining allowing the user to show/hide columns in a GridView to suit their needs.

    Wednesday, April 26, 2006 9:48 PM
  • hi
    Saturday, July 29, 2006 9:09 AM
  • Acording to the GridViewColumn properties (http://windowssdk.msdn.microsoft.com/en-us/library/system.windows.controls.gridviewcolumn_properties.aspx), it looks like to be the best way to accomplish this.

     

    Maybe you can try to change the ColumnTemplate: I can't test now but maube it will work :)

     

    Bye

    Saturday, July 29, 2006 2:45 PM
  • Column visibility...it's an easy enough task to do. I'll make sure that goes into the spec for the WPFToolbelt Grid. Although the GridView is pretty good...it doesn't have a lot of the convenience methods that the DataGridView in Winforms 2.0

    See my blog entry to see the functionality that has been implemented or planned for the first release of the SmartDataGrid.

    Saturday, July 29, 2006 3:29 PM
    Moderator
  • Here i found the solution

    http://www.beansoftware.com/ASP.NET-Tutorials/GridView-Hidden-Column.aspx

    Thanks and Best of Luck

    Asad Naeem

    • Proposed as answer by sshikha Monday, February 08, 2010 9:53 AM
    Friday, December 15, 2006 1:25 PM
  • That's for ASP Gridviews. However, it's good that we could revisit this matter. I think that setting Visibility to collapsed should do what the original poster wants.
    Friday, December 15, 2006 7:05 PM
    Moderator
  • Hello Steven,

    this is for somebody who still has the same problem and needs a solution:

    I had the same problem and  I solved it.

    Can u just name the Gridview using its x:Name property, like

    <GridView x:Name="gvCustomer" >

    and then in programming use this :

    gvCustomer.Columns.RemoveAt(0);


    to hide the first column.

    alternatively you can also use gvCustomer.Columns.Remove to remove a specific gridviewColumn.

    Nilesh
    • Edited by Nilesh Makwana Wednesday, August 20, 2008 7:08 AM comment for reference
    Wednesday, August 20, 2008 7:07 AM
  • Hello all,

    I am having a similar kind of problem and I have not been able to get any solutions so far.

    I have 5 columns in my gridview and I want to hid one of them and show the one hidden in the textbox!
    I have been able to hid the column but when I hid it I can't retive the data from gridview!
    please help me out.


    Thanks to alll in advance
    Wednesday, August 12, 2009 3:51 PM
  • Hello all,

    Use datatable as an datasource.. and before binding to gridview remove column from datatable... tahn bind it in gridview....

    :)

    Happy coding...
    Sunday, September 13, 2009 5:27 PM
  • This works like a charm in VB code behind. Found it by playing around with the inteli-sense. Works great when tied to an ASP Checkbox CheckedChanged event!

    VB.NET EXAMPLE

          GridView1.Columns.Item(3).Visible = False       ' Hide the third column

          GridView1.Columns.Item(3).Visible = True       ' Show the third column
    Friday, January 29, 2010 8:12 PM
  • CaptChris,

    I believe from the initial date on this thread what is talked about here is a ListView with a GridView as a view. This is an object of type 'GridView'. You do have to set the width to zero and there is currently no way around it as far as I know.

    This post is not to disagree with your implementation on the new DataGrid, but others reading this thread might be misled bylooking for the Visible property forever which does not exist.


    noorbakhsh حميد نوربخش
    Friday, January 29, 2010 9:14 PM
  • In order for the GridView1.Columns[colIndex].Visible to work I had to do this in the DataBound event for my gridview. It too is using an ObjectDataSource.
    Thursday, February 04, 2010 4:49 PM
  • Hi,

     I used the solution provided by you i got argument out of range exception.

    I presume this is because i have set auto generate columns to true.

    Can u pl help me get rid of this problem....

    thnx in advance

    Vicky

    Wednesday, April 21, 2010 12:13 PM
  • you can use

     

    Protected Sub SampleGrid_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles SampleGrid.RowCreated

     

    If e.Row.RowType = DataControlRowType.Header Then

    e.Row.Cells(0).Wrap =

    False  --SET WRAPPING OF COLUMN OFF

    e.Row.Cells(1).Text = "Auction GCPM(TC)"  --CHANGE THE HEADER AT RUNTIME

     

    End If

    e.Row.Cells(2).Visible =

    False   --SET THE VISIBILITY OFF FOR COLUMN 2

     

    End Sub
    Saturday, April 23, 2011 8:21 AM