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. DataGridView and System.ComponentModel attributes

DataGridView and System.ComponentModel attributes

Scheduled Pinned Locked Moved C#
winformsquestionlearning
2 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.
  • J Offline
    J Offline
    Jon Hulatt
    wrote on last edited by
    #1

    Hi All, This is Windows Forms, not web. I've got a class, who's properties are normally exposed to my users in a PropertyGrid control. Some of the properties have attributes from the System.ComponentModel namespace to hide, force read only, or rename attributes (DisplayName, ReadOnly, Browsable etc). Now, for some users (those with a superuser access), I need to expose some of the hidden properties, in a DataGridView. But the attributes are causing problems... When I bind a DataGridView to a List of my objects, only the columns shown in the PropertyGrid are shown. Even if I disable automatic column generation, and try to manually create columns, like this:-

                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.DataSource = _my List_;
    
                DataGridViewColumn column = new DataGridViewTextBoxColumn();
                column.Name = "Column Name";
                column.DataPropertyName = "HiddenProperty";
                dataGridView1.Columns.Add(column);
    

    The created column simply comes out blank. Does anyone know a way round this? Other than (of course) losing the databinding functionality and filling the DataGridView manually? Thanks Jon

    using System.Beer;

    J 1 Reply Last reply
    0
    • J Jon Hulatt

      Hi All, This is Windows Forms, not web. I've got a class, who's properties are normally exposed to my users in a PropertyGrid control. Some of the properties have attributes from the System.ComponentModel namespace to hide, force read only, or rename attributes (DisplayName, ReadOnly, Browsable etc). Now, for some users (those with a superuser access), I need to expose some of the hidden properties, in a DataGridView. But the attributes are causing problems... When I bind a DataGridView to a List of my objects, only the columns shown in the PropertyGrid are shown. Even if I disable automatic column generation, and try to manually create columns, like this:-

                  dataGridView1.AutoGenerateColumns = false;
                  dataGridView1.DataSource = _my List_;
      
                  DataGridViewColumn column = new DataGridViewTextBoxColumn();
                  column.Name = "Column Name";
                  column.DataPropertyName = "HiddenProperty";
                  dataGridView1.Columns.Add(column);
      

      The created column simply comes out blank. Does anyone know a way round this? Other than (of course) losing the databinding functionality and filling the DataGridView manually? Thanks Jon

      using System.Beer;

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Hi Jon This is just a shot in the dark, but have you looked into AttributeProvider[^]?

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: How could God prove Himself to humanity? The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      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