Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. hide data grid columns

hide data grid columns

Scheduled Pinned Locked Moved C#
questioncsharpcss
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    theStorminMormon
    wrote on last edited by
    #1

    I just want to hide some columns on my data grid (dynamically). I have my data grid, it's loading the data just fine, and all I want to do is make a column hidden. Here's what I wrote: this.dgClaimsExperience.Columns(1).Visible = false; But C# tells me that System.Windows.Forms.DataGrid does not contain a definition for columns. So... how do I do it? Thanks. The ends can never justify the means. It is the means that determine the ends.

    W 1 Reply Last reply
    0
    • T theStorminMormon

      I just want to hide some columns on my data grid (dynamically). I have my data grid, it's loading the data just fine, and all I want to do is make a column hidden. Here's what I wrote: this.dgClaimsExperience.Columns(1).Visible = false; But C# tells me that System.Windows.Forms.DataGrid does not contain a definition for columns. So... how do I do it? Thanks. The ends can never justify the means. It is the means that determine the ends.

      W Offline
      W Offline
      Wjousts
      wrote on last edited by
      #2

      DataGrid indeed does not contain a columns collection. There are a couple of ways you can handle this, one way is to remove the DataGridColumnStyle for the column you want to hide from DataGrid.TableStyles. The tricky part is that if you want to put it back in it will move to the end of the list and you'll have to rearrange all the other columns (by removing them from the list and then adding them back in the right order). Another way is to set the width of the column (through the DataGridColumnStyle) to zero, but I think the user can still resize it and I think it they can still tab to the column.

      T 1 Reply Last reply
      0
      • W Wjousts

        DataGrid indeed does not contain a columns collection. There are a couple of ways you can handle this, one way is to remove the DataGridColumnStyle for the column you want to hide from DataGrid.TableStyles. The tricky part is that if you want to put it back in it will move to the end of the list and you'll have to rearrange all the other columns (by removing them from the list and then adding them back in the right order). Another way is to set the width of the column (through the DataGridColumnStyle) to zero, but I think the user can still resize it and I think it they can still tab to the column.

        T Offline
        T Offline
        theStorminMormon
        wrote on last edited by
        #3

        Thanks for the suggestions. I think removing the DataGridColumnStyle will work, because in the instance of the form where the data grid is located, I'm never going to want to add the column back in. If you get a chance, post a code snippet for me, otherwise I'm sure I can figure it out on my own. I'd just like to state for the record that I think that DataGrid [i]should[/i] contain a columns collection. It would be useful. Thanks for the help - I'm the only "programmer" (I'm really a mathematical-statistical analyst) in my company so there's no one for me to take my sinple, dumb questions to in person. -stormin The ends can never justify the means. It is the means that determine the ends.

        W 1 Reply Last reply
        0
        • T theStorminMormon

          Thanks for the suggestions. I think removing the DataGridColumnStyle will work, because in the instance of the form where the data grid is located, I'm never going to want to add the column back in. If you get a chance, post a code snippet for me, otherwise I'm sure I can figure it out on my own. I'd just like to state for the record that I think that DataGrid [i]should[/i] contain a columns collection. It would be useful. Thanks for the help - I'm the only "programmer" (I'm really a mathematical-statistical analyst) in my company so there's no one for me to take my sinple, dumb questions to in person. -stormin The ends can never justify the means. It is the means that determine the ends.

          W Offline
          W Offline
          Wjousts
          wrote on last edited by
          #4

          Something like this should work: DataGridColumnStyle dgcs = MyDataGrid.TableStyles["MyTableName"].GridColumnStyles["MyColumnName"]; MyDataGrid.TableStyles["MyTableName"].GridColumnStyles.Remove(dgcs); It's a little more efficient if you keep a reference to the table style and column style objects that you're using so that they don't have to be looked up each time, but the above code should work.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups