473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

Nov 15 '05 #1
5 1682
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" <bo***@datapharm.dk> wrote in message
news:uu**************@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

Nov 15 '05 #2
M
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]" <ni**************@exisconsulting.com> wrote
in message news:O3**************@TK2MSFTNGP11.phx.gbl...
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" <bo***@datapharm.dk> wrote in message
news:uu**************@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


Nov 15 '05 #3
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" <bo***@datapharm.dk> wrote in message
news:uu**************@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

Nov 15 '05 #4
M
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:OF**************@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.


Nov 15 '05 #5
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" <mi******@hotmail.com> wrote in message
news:NV********************@comcast.com...
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:OF**************@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.


Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jez123456 | last post by:
Not sure if I'm in the right thread but here goes. I have an ASP.Net web page with a datagrid. The code behind is C#. If the datagrid has no records the datagrid header section is still shown....
6
by: Das | last post by:
Hi everyone, I'm using datagrid control to display the data. I want to hide column to be displayed into the data grid. I'm using the code as given below: Method given below is used to bind the...
4
by: Tim | last post by:
Hi, I am trying to hide the datagrid row header (the left most column that has the 'select' triangle in it which moves with the selected row). It seems to be fairly simple;...
1
by: enak | last post by:
I populate a datagrid by setting the datasource to a datatable. I then, bind them. After that I try to hide the last column but am not able to. I get an error message. Here is my code: ...
2
by: | last post by:
I have a page where I have 3 combo boxes listed in a column. sort of like: combo1 combo2 combo3 Based on which one is clicked, the others are supposed to hide (i.e. combobox.visible =...
8
by: Hanson | last post by:
I have a datagrid control in an aspx page. The datagrid columns will be dynamically generated according to the pre-page's search condition, I want to hide some columns in the datagrid. is that...
5
by: J | last post by:
Ok, they have changed a lot of stuff in VB.net. How in the world do you hide a column on the Datagrid? -- Jason
2
by: Keithb | last post by:
I need to hide a GridView's "edit" column if the user's role does not support editing. However, the column's Visible property does not support databinding. Is there a workaround? Thanks, ...
9
by: moondaddy | last post by:
using c# 3.5 I have list of business objects which I will use in lists for databinding and I want to hide some of the fields so they don't show up in the list control. some of my list will be:...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.