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

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 1432
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*******@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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
// ArgumentException
// 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.Length; 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
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,...
4
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...
10
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...
6
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...
3
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 ...
7
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...
1
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...
7
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>();...
0
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...
4
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...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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.