How to hide a property on DataGrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Boaz Ben-Porat

    How to hide a property on DataGrid

    Is there an attribute for a property on an object that saus :"This property
    is not shown on a DataGrid" ?

    I know it can be done on the grid itself, using DataGridTableSt yle,
    DataGridColumnS tyle etc. But I`d like to get the same result by changing my
    class, not at run-time changing grid`s behaveiour.

    A small example:

    public class User
    {
    private string m_Uid;
    private string m_Name;
    private string m_Pwd;

    // UID should be visible on a DataGrid
    public string UID
    {
    get {return m_Uid;}
    set {m_Uid = value;}
    }

    // Name should be visible on a DataGrid
    public string Name
    {
    get {return m_Name;}
    set {m_Uid = Name;}
    }
    // PWD should *NOT* be visible on a DataGrid
    //is there an attribute for this ?

    [SomeAttribute.P reventBindingTo Grid(true)] // this is what I`m looking
    for
    public string PWD
    {
    get {return m_Pwd;}
    set {m_Pwd = value;}
    }
    } // End of User.


    On a form with a DataGrid - gridUsers, We implement (implementation not
    shown) a method to fetch users into an ArrayList of User objects, and bind
    gridUsers to the list:

    ArrayList alUsers = FetchUsers();
    gridUsers.DataS ource = alUsers; // Currently, the grid has 3 columns,
    including PWD.
    Can this be done (prevent PWD property from binding) ?

    TIA Boaz Ben-Porat
    DataPharm a/s
    Denmark



  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: How to hide a property on DataGrid

    Boaz,

    Unfortunately not. You will have to change the DataGridColumnS tyle (or
    rather, remove it) as you stated.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - nick(dot)paldin o=at=exisconsul ting<dot>com

    "Boaz Ben-Porat" <boazb@dataphar m.dk> wrote in message
    news:uu9XW8CiDH A.2164@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Is there an attribute for a property on an object that saus :"This[/color]
    property[color=blue]
    > is not shown on a DataGrid" ?
    >
    > I know it can be done on the grid itself, using DataGridTableSt yle,
    > DataGridColumnS tyle etc. But I`d like to get the same result by changing[/color]
    my[color=blue]
    > class, not at run-time changing grid`s behaveiour.
    >
    > A small example:
    >
    > public class User
    > {
    > private string m_Uid;
    > private string m_Name;
    > private string m_Pwd;
    >
    > // UID should be visible on a DataGrid
    > public string UID
    > {
    > get {return m_Uid;}
    > set {m_Uid = value;}
    > }
    >
    > // Name should be visible on a DataGrid
    > public string Name
    > {
    > get {return m_Name;}
    > set {m_Uid = Name;}
    > }
    > // PWD should *NOT* be visible on a DataGrid
    > //is there an attribute for this ?
    >
    > [SomeAttribute.P reventBindingTo Grid(true)] // this is what I`m looking
    > for
    > public string PWD
    > {
    > get {return m_Pwd;}
    > set {m_Pwd = value;}
    > }
    > } // End of User.
    >
    >
    > On a form with a DataGrid - gridUsers, We implement (implementation not
    > shown) a method to fetch users into an ArrayList of User objects, and bind
    > gridUsers to the list:
    >
    > ArrayList alUsers = FetchUsers();
    > gridUsers.DataS ource = alUsers; // Currently, the grid has 3 columns,
    > including PWD.
    > Can this be done (prevent PWD property from binding) ?
    >
    > TIA Boaz Ben-Porat
    > DataPharm a/s
    > Denmark
    >
    >
    >[/color]


    Comment

    • M

      #3
      Re: How to hide a property on DataGrid

      I have this same issue. Can you demonstrate a way to do this cleanly?

      I want to set security so that some people can view some fields, others
      cannot. Hiding from the middle-tier would be cleanest, but you are saying
      this cannot be done. Can you please provide a simple example of how to do
      this your way?

      Thank you!


      "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
      in message news:O3SKaEDiDH A.3208@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Boaz,
      >
      > Unfortunately not. You will have to change the DataGridColumnS tyle[/color]
      (or[color=blue]
      > rather, remove it) as you stated.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - nick(dot)paldin o=at=exisconsul ting<dot>com
      >
      > "Boaz Ben-Porat" <boazb@dataphar m.dk> wrote in message
      > news:uu9XW8CiDH A.2164@TK2MSFTN GP09.phx.gbl...[color=green]
      > > Is there an attribute for a property on an object that saus :"This[/color]
      > property[color=green]
      > > is not shown on a DataGrid" ?
      > >
      > > I know it can be done on the grid itself, using DataGridTableSt yle,
      > > DataGridColumnS tyle etc. But I`d like to get the same result by changing[/color]
      > my[color=green]
      > > class, not at run-time changing grid`s behaveiour.
      > >
      > > A small example:
      > >
      > > public class User
      > > {
      > > private string m_Uid;
      > > private string m_Name;
      > > private string m_Pwd;
      > >
      > > // UID should be visible on a DataGrid
      > > public string UID
      > > {
      > > get {return m_Uid;}
      > > set {m_Uid = value;}
      > > }
      > >
      > > // Name should be visible on a DataGrid
      > > public string Name
      > > {
      > > get {return m_Name;}
      > > set {m_Uid = Name;}
      > > }
      > > // PWD should *NOT* be visible on a DataGrid
      > > //is there an attribute for this ?
      > >
      > > [SomeAttribute.P reventBindingTo Grid(true)] // this is what I`m[/color][/color]
      looking[color=blue][color=green]
      > > for
      > > public string PWD
      > > {
      > > get {return m_Pwd;}
      > > set {m_Pwd = value;}
      > > }
      > > } // End of User.
      > >
      > >
      > > On a form with a DataGrid - gridUsers, We implement (implementation not
      > > shown) a method to fetch users into an ArrayList of User objects, and[/color][/color]
      bind[color=blue][color=green]
      > > gridUsers to the list:
      > >
      > > ArrayList alUsers = FetchUsers();
      > > gridUsers.DataS ource = alUsers; // Currently, the grid has 3 columns,
      > > including PWD.
      > > Can this be done (prevent PWD property from binding) ?
      > >
      > > TIA Boaz Ben-Porat
      > > DataPharm a/s
      > > Denmark
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Ignacio Machin \( .NET/ C#  MVP \)

        #4
        Re: How to hide a property on DataGrid

        Hi,

        There is not such a feature.
        You can implement it, though. Just create a custom Attribute to decorate
        the class and in your new implementation of datagrid you can check for this
        attribute and decide what to do.

        Or just use the *Style properties of the standard grid.


        Cheers,

        --
        Ignacio Machin,
        ignacio.machin AT dot.state.fl.us
        Florida Department Of Transportation


        "Boaz Ben-Porat" <boazb@dataphar m.dk> wrote in message
        news:uu9XW8CiDH A.2164@TK2MSFTN GP09.phx.gbl...[color=blue]
        > Is there an attribute for a property on an object that saus :"This[/color]
        property[color=blue]
        > is not shown on a DataGrid" ?
        >
        > I know it can be done on the grid itself, using DataGridTableSt yle,
        > DataGridColumnS tyle etc. But I`d like to get the same result by changing[/color]
        my[color=blue]
        > class, not at run-time changing grid`s behaveiour.
        >
        > A small example:
        >
        > public class User
        > {
        > private string m_Uid;
        > private string m_Name;
        > private string m_Pwd;
        >
        > // UID should be visible on a DataGrid
        > public string UID
        > {
        > get {return m_Uid;}
        > set {m_Uid = value;}
        > }
        >
        > // Name should be visible on a DataGrid
        > public string Name
        > {
        > get {return m_Name;}
        > set {m_Uid = Name;}
        > }
        > // PWD should *NOT* be visible on a DataGrid
        > //is there an attribute for this ?
        >
        > [SomeAttribute.P reventBindingTo Grid(true)] // this is what I`m looking
        > for
        > public string PWD
        > {
        > get {return m_Pwd;}
        > set {m_Pwd = value;}
        > }
        > } // End of User.
        >
        >
        > On a form with a DataGrid - gridUsers, We implement (implementation not
        > shown) a method to fetch users into an ArrayList of User objects, and bind
        > gridUsers to the list:
        >
        > ArrayList alUsers = FetchUsers();
        > gridUsers.DataS ource = alUsers; // Currently, the grid has 3 columns,
        > including PWD.
        > Can this be done (prevent PWD property from binding) ?
        >
        > TIA Boaz Ben-Porat
        > DataPharm a/s
        > Denmark
        >
        >
        >[/color]


        Comment

        • M

          #5
          Re: How to hide a property on DataGrid

          Anyone have a link to an example of this option? Sounds like exactly what I
          need.


          "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
          in message news:OF7uCBEiDH A.1864@TK2MSFTN GP10.phx.gbl...[color=blue]
          > Hi,
          >
          > There is not such a feature.
          > You can implement it, though. Just create a custom Attribute to decorate
          > the class and in your new implementation of datagrid you can check for[/color]
          this[color=blue]
          > attribute and decide what to do.[/color]



          Comment

          • Ignacio Machin

            #6
            Re: How to hide a property on DataGrid

            Hi M,

            I think remember that a time ago in the MSDN magazine Dino Esposito
            explained something similar, take a look at the msdn archives.


            --
            Hope this help,

            --
            Ignacio Machin,
            ignacio.machin AT dot.state.fl.us
            Florida Department Of Transportation

            "M" <minnow31@hotma il.com> wrote in message
            news:NVSdnXqZ9I J0iOaiXTWJiw@co mcast.com...[color=blue]
            > Anyone have a link to an example of this option? Sounds like exactly what[/color]
            I[color=blue]
            > need.
            >
            >
            > "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >[/color]
            wrote[color=blue]
            > in message news:OF7uCBEiDH A.1864@TK2MSFTN GP10.phx.gbl...[color=green]
            > > Hi,
            > >
            > > There is not such a feature.
            > > You can implement it, though. Just create a custom Attribute to[/color][/color]
            decorate[color=blue][color=green]
            > > the class and in your new implementation of datagrid you can check for[/color]
            > this[color=green]
            > > attribute and decide what to do.[/color]
            >
            >
            >[/color]


            Comment

            Working...