Board index » DotNet » How to hide a property on DataGrid

How to hide a property on DataGrid

DotNet136
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 DataGridTableStyle,

DataGridColumnStyle 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.PreventBindingToGrid(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.DataSource = 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


-
 

Re:How to hide a property on DataGrid

Boaz,



Unfortunately not. You will have to change the DataGridColumnStyle (or

rather, remove it) as you stated.



Hope this helps.





--

- Nicholas Paldino [.NET/C# MVP]

- nick(dot)paldino=at=exisconsulting<dot>com



"Boaz Ben-Porat" <boazb@datapharm.dk>wrote in message

Quote
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 DataGridTableStyle,

DataGridColumnStyle 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.PreventBindingToGrid(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.DataSource = 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











-

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.paldino@exisconsulting.com>wrote

in message news:O3SKaEDiDHA.3208@TK2MSFTNGP11.phx.gbl...

Quote
Boaz,



Unfortunately not. You will have to change the DataGridColumnStyle

(or

rather, remove it) as you stated.



Hope this helps.





--

- Nicholas Paldino [.NET/C# MVP]

- nick(dot)paldino=at=exisconsulting<dot>com



"Boaz Ben-Porat" <boazb@datapharm.dk>wrote in message

news:uu9XW8CiDHA.2164@TK2MSFTNGP09.phx.gbl...

>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 DataGridTableStyle,

>DataGridColumnStyle 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.PreventBindingToGrid(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.DataSource = 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

>

>

>









-

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@datapharm.dk>wrote in message

Quote
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 DataGridTableStyle,

DataGridColumnStyle 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.PreventBindingToGrid(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.DataSource = 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











-

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.machin AT dot.state.fl.us>wrote

in message news:OF7uCBEiDHA.1864@TK2MSFTNGP10.phx.gbl...

Quote
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.







-

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@hotmail.com>wrote in message

Quote
Anyone have a link to an example of this option? Sounds like exactly what

I

need.





"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>

wrote

in message news:OF7uCBEiDHA.1864@TK2MSFTNGP10.phx.gbl...

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











-