473,795 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Properties In C#

Hello there,
I need to code an object with two properties that binds dynamicaly,
something like bind comboboxes on web pages.
So my object needs to gave two properties Prop1 and Prop2. I need
Prop1 to take values from an enum (let's say value1 and value2), and
also Prop2 , depending on the enum selected (at DESIGN TIME) in Prop1,
to take values from two different enums. So if value1 is selected in
Prop1, Prop2 to have a combobox with values (1, 2, 3).But if value2 is
selected in Prop1, then you'll have to choose for Prop2 from values (4,
5, 6).
I'm kind a new with C#, so I'll just want some directions, please.
Regards,
Daniel
Nov 16 '05 #1
4 1451
Here is how you write a property in C#:

class MyComboBox : ComboBox
{
private YourEnum prop1;

public YourEnum Prop1
{
get { return prop1; }
set { prop1 = value; }
}

// do the same for prop2
}

If you add this new combobox to the toolbar and then add the combobox to the
form you will
see those new properties in the Property window.

Note that the notation "prop1" for variable and "Prop1" for the property is
not neccesary.
Also note that "value" is a keyword used in properties whenever you set a
value.
saso

"Daniel Mihaita" <co*******@hotm ail.com> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l...
Hello there,
I need to code an object with two properties that binds dynamicaly,
something like bind comboboxes on web pages.
So my object needs to gave two properties Prop1 and Prop2. I need Prop1
to take values from an enum (let's say value1 and value2), and also Prop2
, depending on the enum selected (at DESIGN TIME) in Prop1, to take values
from two different enums. So if value1 is selected in Prop1, Prop2 to have
a combobox with values (1, 2, 3).But if value2 is selected in Prop1, then
you'll have to choose for Prop2 from values (4, 5, 6).
I'm kind a new with C#, so I'll just want some directions, please.
Regards,
Daniel

Nov 16 '05 #2
Hi Daniel,

I met that way with properties binding.

Let me show you how it works:

Main enum: Vehicles
The good way is to declare *dependant* enums as the same type
e.g. int: Cars, Motorcycles, Bicycles.

public Vehicles Prop1 {
get {
// return "vehicle";
}
set {
// set "vehicle" and set Prop2 on first or default value
}
}

public int Prop2 {
get {
// return "prop2";
}
set {
// if "value" is out of right Enum then throw
// ArgumentExcepti on
// set "prop2" to "value"
}
}

private Type GetProp2Type() {
// return type of dependant enum, e.g. by switch statement
}

HTH
Marcin
Hello there,
I need to code an object with two properties that binds dynamicaly,
something like bind comboboxes on web pages.
So my object needs to gave two properties Prop1 and Prop2. I need
Prop1 to take values from an enum (let's say value1 and value2), and
also Prop2 , depending on the enum selected (at DESIGN TIME) in Prop1,
to take values from two different enums. So if value1 is selected in
Prop1, Prop2 to have a combobox with values (1, 2, 3).But if value2 is
selected in Prop1, then you'll have to choose for Prop2 from values (4,
5, 6).
I'm kind a new with C#, so I'll just want some directions, please.
Regards,
Daniel

Nov 16 '05 #3
Hello Marcin,
I'm not sure I follow you. What I m meant :

public enum Prop1 {Option1, Option2};
public enum Prop2_1:int {opt1_1 , opt1_2};
public enum Prop2_2:int {opt2_1 , opt2_2};

private Prop1 _MainProp;
public Prop1 MainProp
{
get ....
set ....
}

private ????? _SecProp;
public ????? SecProp
{
get ....
set ....
}
At design time, if I choose Option1 for MainProp, then I want that
SecProp let me choose between opt1_1 and opt1_2. And the same, if I
choose Option2, SecProp to let me choose between opt2_1 and opt2_2.
I don't see from you code how to acomplish that.

Regards,
Daniel Mihaita
Nov 16 '05 #4
Hi Daniel,
Hello Marcin,
I'm not sure I follow you. What I m meant :

public enum Prop1 {Option1, Option2};
public enum Prop2_1:int {opt1_1 , opt1_2};
public enum Prop2_2:int {opt2_1 , opt2_2};

private Prop1 _MainProp;
public Prop1 MainProp
{
get ....
set ....
}
It look good till here.

Now i change some of your code:

private int _SecProp;

public int SecProp
{
get ....
set ....
}

So, if you want to set "SecProp" you shoud cast it to "int",
and check the enum type by "MainProp" using:

private Type GetSecPropType( ) {
// return type of dependant enum, e.g. by switch statement
}

e.g.

private bool IsSecPropValue( int val) {
int[] enumValues=(int[]) Enum.GetValues( GetSecPropType( ));
for(int i=0; i<enumValues.Le ngth; i++) {
if( enumValues[i]==val ) {
return true;
}
}
return false;
}

At design time, if I choose Option1 for MainProp, then I want that
SecProp let me choose between opt1_1 and opt1_2. And the same, if I
choose Option2, SecProp to let me choose between opt2_1 and opt2_2.
I don't see from you code how to acomplish that.


I'm afraid that this is impossible to switch those enums
at design time. Only solution is to write your own TypeConverter
or something like that, but it will need much more time.

HTH
Marcin
Nov 16 '05 #5

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

Similar topics

2
3015
by: Rick Austin | last post by:
I recently had to perform a reinstalltion of Windows XP (my registry seems to have become corrupt). After this completed I had to reinstall all applications since most use the registry for settings, etc. After installing VS.NET 2003 everything seemed to work okay with one exception, none of the project properties appear. If I right click a project and select properties, the properties dialog appears and the property category tree is dispayed but...
4
7516
by: Lyn | last post by:
Hi, This question may seem a bit academic... To learn more about Access VBA, I have been enumerating the properties of various form controls. This was mostly successful and I have learned a lot from the process. It occurred to me that I could also enumerate the properties of the ADO Recordset in similar fashion, expecting to get back known properties such as AbsolutePosition, BOF, EOF, Filter, Sort, etc. I inserted the following
10
7372
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a Windows.Forms.UserControl in a COM environment, i.e. I want to host that control in a COM host. So far, so good, I can host it, but I can not reach the parent COM object from the control (Parent property is null :( ). I have stopped the control in the...
6
5185
by: JerryP | last post by:
Hello, is there a way to launch the property dialogue for a directory from my c# app ? I would also like to launch the User Account Properties from Active Directory Users and Computers, and the properties window for an Object in Active Directory. Thanks for any hints.
3
5079
by: Martin Montgomery | last post by:
I have, for example, a property called myProperty. I would like, when using a property grid to display the property name as "My Property". Is this possible. Is there an attribute etc Thank Martin
7
8534
by: Donald Grove | last post by:
Is it possible to retrieve field properties from a table in access2000 using code? I have tried: " dim dbs as dao.database dim tbl as dao.tabledef dim fld as dao.field dim prop as dao.property
1
1691
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled by their underlying classes (such as the TextBox control), and are not persisted by me. 2.) Unique Properties that don't map directly and are persisted in ViewState (ex.: this.LabelPosition, which specifies where on the form the label should be...
7
6070
by: Anderskj | last post by:
Hi! I am developing a c# application. I have a interface (which can change therefore my problem) If i do like this: List<PropertyInfoproperties = new List<PropertyInfo>(); properties.AddRange(typeof(app.IView).GetProperties());
0
2853
by: =?Utf-8?B?UmljayBHbG9z?= | last post by:
For some unknown reason (user error?), I cannot get a NameValueCollection to persist in the app.config file. Unlike other settings, I cannot get the String Collection Editor GUI to allow my to add/edit any values for a setting with type NameValueCollection. Nor can I get a NameValueCollection to persist to the User Settings via code using a simple C# Console App... Is this a user error or ?
4
9864
by: FullBandwidth | last post by:
I have been perusing various blogs and MSDN pages discussing the use of event properties and the EventHandlerList class. I don't believe there's anything special about the EventHandlerList class in this context, in fact some articles from pre-2.0 suggest using any collection class of your choice. So my questions focus more on the syntax of event properties provided by the "event" keyword in C#. (Disclaimer - I am a C++ programmer working...
0
9673
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
10216
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...
1
10165
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
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
9044
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
7543
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...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.