Control Property Refresh

  • Thread starter Thread starter Tomer
  • Start date Start date
T

Tomer

I Created 3 Properties to my Control Mindate(retuns date) MaxDate ( return
date )
and a CustomList Property (allDates,Uptodate...)
when i choose from the list allDates for example the Mindate and MaxDate are
set to the values i set in the method for the CustomList,
The thing is that in Design time when i select allDates i don't see the
changes on minDate and maxDate, only when i click on them(on the property
box) they change to the currect date,
How can i make them change immidiatly in Design time when i select allDates
etc,,,,

Thanks

Tomer
 
Try marking the property with the RefreshPropertiesAttribute.

Something like this:

[RefreshPropertiesAttribute(RefreshProperties.All)]
public listEnum CustomList
{
get { return listEnumValue; }
set
{
if (listEnumValue != value)
{
listEnumValue = value;
//reset other properties here
}
}
}

HTH;
Eric Cadwell
http://www.origincontrols.com
 
Hi Eric,
I tried it and again, i can see the change only when i click on the
property (mindate or maxdate)
isn't there a way that the properties will change automaticly as i
change the list values ?
 
Am I correct to say that when you set the custom list property, you
internally set the mindate and maxdate?
Is it your intention to have mindate and maxdate editable at design-time? If
not, you can hide them from the property grid.

Not sure what the issue is, as this code works for me:

public enum CustomList{All, Past, Future}

public class UserControl1 : System.Windows.Forms.UserControl
{
private CustomList customListValue = CustomList.All;
private DateTime minDate = DateTime.MinValue;
private DateTime maxDate = DateTime.MaxValue;

[RefreshPropertiesAttribute(RefreshProperties.All)]
public CustomList CustomList
{
get { return customListValue; }
set
{
if (customListValue != value)
{
customListValue = value;

//reset other properties here
DateTime newMin = DateTime.MinValue;
DateTime newMax = DateTime.MaxValue;
switch (value)
{
case CustomList.Future:
newMin = DateTime.Now;
break;
case CustomList.Past:
newMax = DateTime.Now;
break;
}
MinDate = newMin;
MaxDate = newMax;
}
}
}
public DateTime MinDate
{
get { return minDate; }
set { minDate = value; }
}
public DateTime MaxDate
{
get { return maxDate; }
set { maxDate = value; }
}
}

If I remove the RefreshProperties attribute it stops updating, but with the
attribute applied MinDate and MaxDate update accordingly in the designer
when CustomList changes.

HTH;
Eric Cadwell
http://www.origincontrols.com
 
GREAT ! this Works,
I have another small question....:(
If i want to go the other way arround.
lets say to add "Custom: to my enum list and whenever the user will
change the min/max date properties by himself the "Custom" will appear
on top in the enum control list.

Or - another idea..is there a way to hide the min/max properties from
the developer and show the when he chooses
"Custom".


Tomer
 
Sounds like a bit more code.

To change the value to custom you would just need to set conditions upon
which a value is custom...

For example:
public DateTime MinDate
{
get { return minDate; }
set
{
if (customListValue != CustomList.Future && value != DateTime.MinValue)
customListValue = CustomList.Custom;

minDate = value;
}
}

The second route sounds possible, but it would require a lot more work.

-Eric
 
Back
Top