473,794 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<someClassl ist
Observable collections
and
a custom list derived from the BindingList.

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

Thanks.
--
mo*******@newsg roup.nospam
Sep 26 '08 #1
9 9769
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(obje ct sender, EventArgs e)
{
List<Customerar r = 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.dataGridVi ew1.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****@microsof t.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.mic rosoft.comwrote in message
news:Zg******** ******@TK2MSFTN GHUB02.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(obje ct sender, EventArgs e)
{
List<Customerar r = 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.dataGridVi ew1.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****@microsof t.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 DisplayMemberBi nding or DisplayMemberPa th 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****@microsof t.com.

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

Sep 29 '08 #5
DisplayMemberBi nding or DisplayMemberPa th 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 observablecolle ction with no luck.
"Zhi-Xin Ye [MSFT]" <v-****@online.mic rosoft.comwrote in message
news:nF******** ******@TK2MSFTN GHUB02.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 DisplayMemberBi nding or DisplayMemberPa th 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****@microsof t.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****@microsof t.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.mic rosoft.comwrote in message
news:lL******** ******@TK2MSFTN GHUB02.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****@microsof t.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****@microsof t.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.mic rosoft.comwrote in message
news:wY******** ******@TK2MSFTN GHUB02.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****@microsof t.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
12659
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
1167
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 from Collections.ObjectModel.Collection(Of Customer) and do this instead: Public Class Customers Private lst As New Collections.Generic.List(Of Customer) End Class And then add my own methods (private Add, Public Count and so on) to work
1
9358
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 GridView.Visible = True. I press HIDE and the GridView disappears as expected. After it I press SHOW and the GridView doesn't show.
1
6054
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 correct attribute to apply on my field.
7
6409
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"> ... </div>
0
975
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 : "MyTitle - Theme A" The problem is that labels, which are binded to theses fields, return me an error :
4
5763
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 is looping through the repeater: Dim rc As RepeaterItemCollection = rptReport.Items Dim ri As RepeaterItem Dim chkSelected As System.Web.UI.WebControls.CheckBox Dim customer As String
0
1661
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 <Headerelement that I'd like to add the 'Run' attribute for each record in the TA_HeaderID field. So, in the example, '879" would be added to each record in the TA_HeaderID field. Schema file... <?xml version="1.0" encoding="utf-8"?>
5
1985
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 linked table called tblComponents and then I bounded the original forms to this new table. I did change the control source: Description (Field name) RowSource Type: Table/Query (which remains the same)
0
9671
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9035
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.