473,395 Members | 1,653 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.

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 9724
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Flix | last post by:
When I extend a Control and I want to hide a property at design time, I do: public class MyButton : Button { public new System.String Text { get{return base.Text;} set{base.Text=value;} }
0
by: Michael Fällgreen | last post by:
I'm in a jam here. I need to make my own collection of customers to simplify the inteface (don't want Add, CopyTo, Contains and so on - need a nice clean interface). I can do this by NOT inherit...
1
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
1
by: zolof | last post by:
Hi. I am using VS2005 and C# for a Windows Form app. I have made a user control and added a public field. Is there a way so it does not appear in the designer property tab ? I cannot find the...
7
by: Giacomo | last post by:
I work on a page structured like: <h2> ... </h2> <div ="div1" class="show"> ... </div> <h2> ... </h2> <div id="div2" class="show"> ... </div> <h2> ... </h2> <div id="div3" class="show">...
0
by: gouraud | last post by:
Hello, I'm working on Visual Web Developper (ASPX with C# code Behind) I would like to fill a DataList with items using this format (with as item as elements) : "file - element", example :...
4
by: adiel_g | last post by:
I am trying to loop through a repeater to retrieve a dataitem field but am getting a NullReferenceException. I can find a checkbox control but cannot find a dataitem field. Here is the code that...
0
by: JimP | last post by:
I'm importing XML files into a SQLExpress DB using SQLXML and VB.net 2005. I have a simple *.xsd schema file that is pulling in all attributes from the <Activityelement. It also has a...
5
by: agarwasa2008 | last post by:
Hi, I have a linked table called tbltest and some bounded forms (which add, update, delete records) that were created using that linked table. For some necessary reasons I had to create another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.