473,385 Members | 1,409 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,385 software developers and data experts.

Property Attributes c#

I am displaying a list of properties on my GUI. All the properties
have combo boxes that shouldn't be allowed to be edited. At the minute
this works fine for bool values, see the code below for the Enabled
property:

[Category("Behaviour")]
[Description("Indicates if Button is Enabled or not")]
[BrowsableAttribute(true)]
public bool Enabled

The problem is that I have a few properties with custom types. When
being displayed these combo boxes allow the user to manually type into
the combo box. I do not want this to happen. Is there a property that
restricts the user from typing into the combo box? If not how should I
do this? An example of a property that allows the user to edit the
text in the combo box is below: Any ideas on how to prevent this?

[Browsable(true)]
[TypeConverter(typeof(StateConverter))]
[Description("Should Button be Hidden, Mandatory or Optional")]
public string State

Mar 14 '06 #1
5 9870

<si***********@yahoo.co.uk> wrote in message
news:11*********************@j52g2000cwj.googlegro ups.com...
I am displaying a list of properties on my GUI. All the properties
have combo boxes that shouldn't be allowed to be edited. At the minute
this works fine for bool values, see the code below for the Enabled
property:

[Category("Behaviour")]
[Description("Indicates if Button is Enabled or not")]
[BrowsableAttribute(true)]
public bool Enabled

The problem is that I have a few properties with custom types. When
being displayed these combo boxes allow the user to manually type into
the combo box. I do not want this to happen. Is there a property that
restricts the user from typing into the combo box? If not how should I
do this? An example of a property that allows the user to edit the
text in the combo box is below: Any ideas on how to prevent this?

[Browsable(true)]
[TypeConverter(typeof(StateConverter))]
[Description("Should Button be Hidden, Mandatory or Optional")]
public string State


I assume that you mean that you are using PropertyGrid.

See ReadonlyAttribute
Mar 14 '06 #2
Yes I am using PropertyGrid.

Unfortunately ReadonlyAttribute does not work. It simply restricts all
input to that property. I would like the user to be able to choose
values from the property drop down but not be able to edit these values
manually.

Mar 14 '06 #3
Yes I am using PropertyGrid.

Unfortunately ReadonlyAttribute does not work. It simply restricts all
input to that property. I would like the user to be able to choose
values from the property drop down but not be able to edit these values
manually.

Mar 14 '06 #4
Hi,
[Browsable(true)]
[TypeConverter(typeof(StateConverter))]
[Description("Should Button be Hidden, Mandatory or Optional")]
public string State


If you get a combobox for this string property (I see that you have type
converter assigned) that means the type converter supports standard values
that is GetStandardValuesSupported is overridden and returns *true*.

If the combobox is populated that also means you have overridden
GetStandardValues and return collection of standard values.

So far the prop grid shows populated combobox, but the text in the property
grid is editable.

There is one small little step that you need to do in order to make to
behave like the comboboxes for enumerations and bool type. Override
GetStandardValuesExclusive and return *true*. This way the text cannot be
editer and only the values from the list can be used.

My question, though is why you don't use enumeration instead of string if
the possible values (Hidden, Mandatory and Optional) are fixed and
predefined?
--
HTH
Stoitcho Goutsev (100)
Mar 14 '06 #5
Thanks Stoitcho, overriding GetStandardValuesExclusive to return true
solved the problem for me. I am not sure why the application is set up
this way as I didn't write it. I'll mention your suggestion to the
other developers. Thanks.

Mar 15 '06 #6

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

Similar topics

6
by: manuel | last post by:
Exist a sintax like import Foo for property in Foo print property ?
1
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a...
3
by: Gigi | last post by:
I'm trying to add a custom property to each row of a table. So I created an HtmlTable called tblClass, I created a new class myRow inherited from HtmlTableRow, to which I added a new member myRow ...
3
by: Marty McFly | last post by:
Hello, I have a control class that inherits from System.Web.UI.WebControls.Button. When I drag this control from the "My User Controls" tab in the toolbox onto the form, I want it to reflect the...
3
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what...
13
by: Robert Bravery | last post by:
HI all, I created a property callsed closed with in a select tag for each option. The property is then assigned a value of 0 or 1. I then evaluate this property in a JS script When I do this...
5
by: Kimmo Laine | last post by:
Hi is there a way to change propertys attribute from the code? Letīs say that i have the following property in my class: public int Count } Is there a way to change the displayname, from...
11
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
5
by: Rafe | last post by:
Hi, I've been thinking in circles about these aspects of Pythonic design and I'm curious what everyone else is doing and thinks. There are 3 issues here: 1) 'Declaring' attributes - I...
8
by: Hussein B | last post by:
Hey, I noted that Python encourage the usage of: -- obj.prop = data x = obj.prop -- to set/get an object's property value. What if I want to run some logic upon setting/getting a property?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.