MSDN > 論壇首頁 > Windows Presentation Foundation (WPF) > How to show/hide column in GridView
發問發問
 

已答覆How to show/hide column in GridView

  • 2006年3月1日 上午 09:23Steven Khiem 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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

解答

  • 2006年3月1日 下午 04:08MichaelLatta版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    To hide a column just set the width to 0.  To show it again set the width to auto.
  • 2006年12月15日 下午 07:05Brownie PointsMVP, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    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.

所有回覆

  • 2006年3月1日 下午 04:08MichaelLatta版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    To hide a column just set the width to 0.  To show it again set the width to auto.
  • 2006年3月2日 上午 02:16Steven Khiem 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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

  • 2006年3月3日 上午 06:41zhili 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    How about using add/remove column since GridView is just a "view" of tabular data. Is that ok for your scenario?
  • 2006年3月9日 上午 01:56Steven Khiem 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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

  • 2006年3月9日 上午 02:48zhili 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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. 

  • 2006年3月22日 下午 09:48James_Lin 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    use this
    GridView1.Columns[0].Visible = false;
  • 2006年3月29日 下午 08:03Ahmed_khemiri 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    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.
  • 2006年4月26日 下午 09:48WPFMonkey 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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.

  • 2006年7月29日 上午 09:09rupesh_Sidpara 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    hi
  • 2006年7月29日 下午 02:45Thomas LEBRUNMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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

  • 2006年7月29日 下午 03:29Brownie PointsMVP, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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.

  • 2006年12月15日 下午 01:25asadnaeem 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Here i found the solution

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

    Thanks and Best of Luck

    Asad Naeem

  • 2006年12月15日 下午 07:05Brownie PointsMVP, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    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.
  • 2008年8月20日 上午 07:07Nilesh Makwana 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    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
    • 已編輯Nilesh Makwana 2008年8月20日 上午 07:08comment for reference
    •  
  • 2009年8月12日 下午 03:51SoftProgrammerr 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    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
  • 2009年9月13日 下午 05:27ilasuper 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hello all,

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

    :)

    Happy coding...