473,404 Members | 2,170 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,404 software developers and data experts.

How to create dependant properties???????

Hi all, I'm creating a simple user control that has two properties that
represent a range of valid integer values.
For example:

int minimum, maximum;

public int Minimum
{
get { return mimimum; }
set { minimum = value; }
}

public int Maximum
{
get { return maximum; }
set { maximum= value; }
}

// P.S. I've deliberately made this simple to avoid cluttering code.

Using the properties window, I would like the programmer to be able to set
the minimum and maximum values to a proper
range - for example Minimum = 400 and Maximum = 800.

The rules are that the minimum value must be <= to the maximum value and the
maximum value must be >= to the minimum
value (a circular dependance on each other). Thus, setting the properties to
Minimum = 800 and Maximum = 400 would be illegal and the code would prevent
this.

Does anyone know of a way of doing this using two separate properties or can
it be done with one property or some other method I may have overlooked? Any
ideas would be appreciated.

Regards,
Paul



Nov 16 '05 #1
4 1155
Paul Loveless wrote:
int minimum, maximum;

public int Minimum
{
get { return mimimum; }
set { minimum = value; }
}

public int Maximum
{
get { return maximum; }
set { maximum= value; }
}

The rules are that the minimum value must be <= to the maximum value
and the maximum value must be >= to the minimum
value (a circular dependance on each other). Thus, setting the
properties to Minimum = 800 and Maximum = 400 would be illegal and the
code would prevent this.

Does anyone know of a way of doing this using two separate properties
or can it be done with one property or some other method I may have
overlooked? Any ideas would be appreciated.


int minimum = 0;
int maximum = 0;

[DefValue((int) 0)]
public int Minimum
{
get { return mimimum; }
set
{
if (value >= maximum)
throw System.ApplicationExcetion("Min must be less or equal max";
minimum = value;
}
}

[DefValue((int) 0)]
public int Maximum
{
get { return maximum; }
set
{
if (value <= minumum)
throw System.ApplicationExcetion("Max must be greater or equal
min";
maximum = value;
}
}

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
Nov 16 '05 #2
Paul,

When checking the value that is passed in, why not check against the
private properties that you are returning, and not the actual property
itself (which causes the callback).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paul Loveless" <pa****@rogers.com> wrote in message
news:Hx********************@news04.bloor.is.net.ca ble.rogers.com...
Hi all, I'm creating a simple user control that has two properties that
represent a range of valid integer values.
For example:

int minimum, maximum;

public int Minimum
{
get { return mimimum; }
set { minimum = value; }
}

public int Maximum
{
get { return maximum; }
set { maximum= value; }
}

// P.S. I've deliberately made this simple to avoid cluttering code.

Using the properties window, I would like the programmer to be able to set
the minimum and maximum values to a proper
range - for example Minimum = 400 and Maximum = 800.

The rules are that the minimum value must be <= to the maximum value and the maximum value must be >= to the minimum
value (a circular dependance on each other). Thus, setting the properties to Minimum = 800 and Maximum = 400 would be illegal and the code would prevent this.

Does anyone know of a way of doing this using two separate properties or can it be done with one property or some other method I may have overlooked? Any ideas would be appreciated.

Regards,
Paul


Nov 16 '05 #3
if (value >= maximum)
throw System.ApplicationExcetion("Min must be less or equal max";
minimum = value;


or an ArgumentOutOfRangeException

Pedantic I know.
JB
Nov 16 '05 #4
Sorry for the late reply. I'll have to try that.

Paul

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ew**************@tk2msftngp13.phx.gbl...
Paul,

When checking the value that is passed in, why not check against the
private properties that you are returning, and not the actual property
itself (which causes the callback).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paul Loveless" <pa****@rogers.com> wrote in message
news:Hx********************@news04.bloor.is.net.ca ble.rogers.com...
Hi all, I'm creating a simple user control that has two properties that
represent a range of valid integer values.
For example:

int minimum, maximum;

public int Minimum
{
get { return mimimum; }
set { minimum = value; }
}

public int Maximum
{
get { return maximum; }
set { maximum= value; }
}

// P.S. I've deliberately made this simple to avoid cluttering code.

Using the properties window, I would like the programmer to be able to set the minimum and maximum values to a proper
range - for example Minimum = 400 and Maximum = 800.

The rules are that the minimum value must be <= to the maximum value and the
maximum value must be >= to the minimum
value (a circular dependance on each other). Thus, setting the

properties to
Minimum = 800 and Maximum = 400 would be illegal and the code would

prevent
this.

Does anyone know of a way of doing this using two separate properties or

can
it be done with one property or some other method I may have overlooked?

Any
ideas would be appreciated.

Regards,
Paul



Nov 16 '05 #5

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

Similar topics

3
by: Brian van den Broek | last post by:
Hi all, I'm just starting to employ unit testing (I'm using doctest), and I am uncertain how to handle writing tests where the behaviour being tested is dependant on whether certain file paths...
6
by: PT | last post by:
I got a form with many text boxes, checkboxes and 3 drop downs. From that 3, 2 are dependant. I can choose one drop down, and the next drop down should display the dependant values of the first...
6
by: Marek Mänd | last post by:
I searched google but couldnt find ant decent code for dependant comboboxes script (where the combo values in other combo depend upon the selections in the first combobox). The problem is that...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
3
by: Kent | last post by:
I am try to link a SQL 2000 table to Access 2000 using VB.Net 2003 Here is my code: Dim Con As New ADODB.Connection Dim Cat As New ADOX.Catalog Dim tbl As New ADOX.Table ...
1
by: ScottL | last post by:
Hello, I have a asp.net Visual Basic web solution with 3 projects: A user interface project (ProjectUI), a Business Object Layer project (ProjectBOL) and a Data Access Layer Project...
5
by: moondaddy | last post by:
I want to create a custom UI element which will be a custom rectangle object in a c# XAML application. I'm new to XAML and c# as most of my experience has been using vb with sql. I'm building a...
6
by: py_genetic | last post by:
Is this possible or is there a better way. I need to create a new class during runtime to be used inside a function. The class definition and body are dependant on unknows vars at time of exec,...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
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:
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...
0
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,...
0
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...

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.