471,310 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Need an attribute to hide a field when databinding

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:
List<someClasslist
Observable collections
and
a custom list derived from the BindingList.

[someAttribute]
public int SomeField
{
get...
set...
}

Thanks.
--
mo*******@newsgroup.nospam
Sep 26 '08 #1
9 9448
Dear moondaddy,

As I understand, you have a list of business objects, when performing data
binding, you want some of the properties in the custom class not be
displayed in the list control.

You can use the Browsable attribute, setting it to false would make the
property hidden when performing data binding. e.g.

============== Code Sample ===============

class Customer
{
private int id;
private string name;
private string coutry;

public Customer(int id, string name, string coutry)
{
this.id = id;
this.name = name;
this.coutry = coutry;
}

public int ID
{
get { return id; }
set { this.id = value; }
}

[Browsable(false)]
public string Name
{
get { return name; }
set { this.name = value; }
}

public string Country
{
get { return coutry; }
set { this.coutry = value; }
}
}

private void Form2_Load(object sender, EventArgs e)
{
List<Customerarr = new List<Customer>();
arr.Add(new Customer(1, "Zhang", "China"));
arr.Add(new Customer(2, "John", "US"));
arr.Add(new Customer(3, "Ricky", "UK"));
arr.Add(new Customer(4, "Hkjer", "UK"));
arr.Add(new Customer(5, "Rbtrw", "DE"));
arr.Add(new Customer(6, "Ricky", "AU"));
arr.Add(new Customer(7, "Griao", "FR"));

this.dataGridView1.DataSource = arr;
}

=============================================

When running the code, you'll find the "Name" property is not displayed in
the DataGridView.

Should you have any questions, please feel free to let me know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 26 '08 #2
For the UI: [Browsable(false)]

For intellisense: [EditorBrowsable(blah.Never)]

Marc
Sep 26 '08 #3
Thanks,

I tested this and it did work in a winforms app, but doesnt work in a wpf
app. I should have specified that I was working in wpf, but I didnt think
it made a difference until now. Do you know what I need to do to make this
work in wpf?
"Zhi-Xin Ye [MSFT]" <v-****@online.microsoft.comwrote in message
news:Zg**************@TK2MSFTNGHUB02.phx.gbl...
Dear moondaddy,

As I understand, you have a list of business objects, when performing data
binding, you want some of the properties in the custom class not be
displayed in the list control.

You can use the Browsable attribute, setting it to false would make the
property hidden when performing data binding. e.g.

============== Code Sample ===============

class Customer
{
private int id;
private string name;
private string coutry;

public Customer(int id, string name, string coutry)
{
this.id = id;
this.name = name;
this.coutry = coutry;
}

public int ID
{
get { return id; }
set { this.id = value; }
}

[Browsable(false)]
public string Name
{
get { return name; }
set { this.name = value; }
}

public string Country
{
get { return coutry; }
set { this.coutry = value; }
}
}

private void Form2_Load(object sender, EventArgs e)
{
List<Customerarr = new List<Customer>();
arr.Add(new Customer(1, "Zhang", "China"));
arr.Add(new Customer(2, "John", "US"));
arr.Add(new Customer(3, "Ricky", "UK"));
arr.Add(new Customer(4, "Hkjer", "UK"));
arr.Add(new Customer(5, "Rbtrw", "DE"));
arr.Add(new Customer(6, "Ricky", "AU"));
arr.Add(new Customer(7, "Griao", "FR"));

this.dataGridView1.DataSource = arr;
}

=============================================

When running the code, you'll find the "Name" property is not displayed in
the DataGridView.

Should you have any questions, please feel free to let me know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 26 '08 #4
Dear moondaddy,

As far as I know there is not such an attribute in WPF. However, if you
don't want to show the field in the control, you can just don't assign that
field for the DisplayMemberBinding or DisplayMemberPath property. Could you
please explain your scenario in more details?

I look forward to your reply.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 29 '08 #5
DisplayMemberBinding or DisplayMemberPath properties don't apply here. I
have a grid (in this case its a grid from Infragistics) and set its data
source like this:

grid.DataSource = myList;

and I waned to use an attribute to hide some of the props in the business
objects in myList. I even tried the observablecollection with no luck.
"Zhi-Xin Ye [MSFT]" <v-****@online.microsoft.comwrote in message
news:nF**************@TK2MSFTNGHUB02.phx.gbl...
Dear moondaddy,

As far as I know there is not such an attribute in WPF. However, if you
don't want to show the field in the control, you can just don't assign
that
field for the DisplayMemberBinding or DisplayMemberPath property. Could
you
please explain your scenario in more details?

I look forward to your reply.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.

Oct 10 '08 #6
Dear moondaddy,

I'm not familiar with the infragistics DataGrid, but as far as I know
there's no such attribute in WPF. Would you mind trying in another way? For
example, you can hide the fields which you don't need from the grid. I
find some threads on the internet on how to hide a field from the
Infragistics DataGrid.

Threads for your information:

Using xamdatagrid to hide columns programmically
http://forums.infragistics.com/forums/p/8493/33545.aspx

how to control columns display when displaying hierarchical data using
XamDataGrid
http://forums.infragistics.com/forums/p/2568/15732.aspx

Should you have any questions, please don't hesitate to let me know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
Oct 10 '08 #7
Thanks,

Yes I can write code to hide those columns in the grid, but I was hoping I
could use an attribute. I codegen my custom list classes and it's real easy
to assign attributes in the code generator. if I know ahead of time what
properties I don't want to be visible in the UI, I can just assign the
attribute to the property or field one time and then when every the business
object is used in a list, I only see what I want to see. This greatly
simplifies things.

Thanks again.
"Zhi-Xin Ye [MSFT]" <v-****@online.microsoft.comwrote in message
news:lL**************@TK2MSFTNGHUB02.phx.gbl...
Dear moondaddy,

I'm not familiar with the infragistics DataGrid, but as far as I know
there's no such attribute in WPF. Would you mind trying in another way?
For
example, you can hide the fields which you don't need from the grid. I
find some threads on the internet on how to hide a field from the
Infragistics DataGrid.

Threads for your information:

Using xamdatagrid to hide columns programmically
http://forums.infragistics.com/forums/p/8493/33545.aspx

how to control columns display when displaying hierarchical data using
XamDataGrid
http://forums.infragistics.com/forums/p/2568/15732.aspx

Should you have any questions, please don't hesitate to let me know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.


Oct 15 '08 #8
Dear moondaddy,

Yes I know it would make things easy if we had an attribute to hide the
field when binding, I would suggest you post this feature as a suggestion
to our Connect feedback portal. Our developer
will evaluate it seriously and take them into consideration when designing
furture release of the product.

Here is the link for the Connect feedback portal:

http://connect.microsoft.com/VisualStudio/

For the time being, you can write code to hide the columns in the grid,
sorry for any inconvenience this may cause.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can

improve the support we provide to you. Please feel free to let my manager
know what you think of the level

of service provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 17 '08 #9
Will do. Thanks.

"Zhi-Xin Ye [MSFT]" <v-****@online.microsoft.comwrote in message
news:wY**************@TK2MSFTNGHUB02.phx.gbl...
Dear moondaddy,

Yes I know it would make things easy if we had an attribute to hide the
field when binding, I would suggest you post this feature as a suggestion
to our Connect feedback portal. Our developer
will evaluate it seriously and take them into consideration when designing
furture release of the product.

Here is the link for the Connect feedback portal:

http://connect.microsoft.com/VisualStudio/

For the time being, you can write code to hide the columns in the grid,
sorry for any inconvenience this may cause.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can

improve the support we provide to you. Please feel free to let my manager
know what you think of the level

of service provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.

Oct 21 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Flix | last post: by
reply views Thread by Michael Fällgreen | last post: by
7 posts views Thread by Giacomo | last post: by
reply views Thread by gouraud | last post: by
reply views Thread by rosydwin | last post: by

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.