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. Datagrid formatting

Datagrid formatting

Scheduled Pinned Locked Moved C#
databasequestionworkspace
4 Posts 3 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.
  • E Offline
    E Offline
    esjq
    wrote on last edited by
    #1

    Hi! Is it possible to hide columns in the datagrid? When using the original setup of the datagrid every column is displayed. And if you would like to populate the datagrid with information from a database, it displays the primary key and foreign key columns as well. Is there a way to hide an arbitrary column in the datagrid, but still being able to reach the value of the it behind the scenes? Thank you! :)

    J L E 3 Replies Last reply
    0
    • E esjq

      Hi! Is it possible to hide columns in the datagrid? When using the original setup of the datagrid every column is displayed. And if you would like to populate the datagrid with information from a database, it displays the primary key and foreign key columns as well. Is there a way to hide an arbitrary column in the datagrid, but still being able to reach the value of the it behind the scenes? Thank you! :)

      J Offline
      J Offline
      John Fisher
      wrote on last edited by
      #2

      Sounds like you need to look into using the DataView. Research to see if it fits your needs, then ask again if you need more info. John
      "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

      1 Reply Last reply
      0
      • E esjq

        Hi! Is it possible to hide columns in the datagrid? When using the original setup of the datagrid every column is displayed. And if you would like to populate the datagrid with information from a database, it displays the primary key and foreign key columns as well. Is there a way to hide an arbitrary column in the datagrid, but still being able to reach the value of the it behind the scenes? Thank you! :)

        L Offline
        L Offline
        Luis Alonso Ramos
        wrote on last edited by
        #3

        Yes, check the DataGridTableStyle class. The basic idea is that you create one DataGridTableStyle object, and then add DataGridTextBoxColumn or other column types (check boxes por example) to the table style, only for the columns you want to display (use the MappingName property). Here's an example, from some code I'm working on right now:

        DataGridTableStyle style = new DataGridTableStyle();
        style.MappingName        = dtZoneCollectors.TableName;
        
        DataGridTextBoxColumn textCol = new DataGridTextBoxColumn();
        textCol.MappingName           = "column_name";
        textCol.HeaderText            = "Name as it will appear to the user";
        textCol.Width                 = 200;
        textCol.ReadOnly              = true;
        style.GridColumnStyles.Add(textCol);
        
        gridCollectors.TableStyles.Add(style);
        

        It only adds one column, but hopefully you'll get the idea. Good luck! -- LuisR


        Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

        1 Reply Last reply
        0
        • E esjq

          Hi! Is it possible to hide columns in the datagrid? When using the original setup of the datagrid every column is displayed. And if you would like to populate the datagrid with information from a database, it displays the primary key and foreign key columns as well. Is there a way to hide an arbitrary column in the datagrid, but still being able to reach the value of the it behind the scenes? Thank you! :)

          E Offline
          E Offline
          esjq
          wrote on last edited by
          #4

          Thank you! :)

          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