Click here to Skip to main content
15,902,114 members
Home / Discussions / C#
   

C#

 
GeneralRe: app config file issue Pin
Dave Kreskowiak4-Nov-08 6:51
mveDave Kreskowiak4-Nov-08 6:51 
GeneralRe: app config file issue Pin
George_George6-Nov-08 2:50
George_George6-Nov-08 2:50 
GeneralRe: app config file issue Pin
Dave Kreskowiak7-Nov-08 13:19
mveDave Kreskowiak7-Nov-08 13:19 
QuestionThreading Pin
caradri30-Oct-08 3:25
caradri30-Oct-08 3:25 
AnswerRe: Threading Pin
Eddy Vluggen30-Oct-08 4:10
professionalEddy Vluggen30-Oct-08 4:10 
AnswerRe: Threading Pin
Giorgi Dalakishvili30-Oct-08 4:13
mentorGiorgi Dalakishvili30-Oct-08 4:13 
QuestionModal Dialog Behavior Problem Pin
selcuks30-Oct-08 3:19
selcuks30-Oct-08 3:19 
QuestionCan somebody translate this and tell me what it means Pin
netJP12L30-Oct-08 2:53
netJP12L30-Oct-08 2:53 
I am wondering if there is a way (perhaps through Attributes) that I can indicate to a PropertyGrid that I want a certain Property (which is an int) of a class MyClass to be limited to a given range, say 0-10. I know I could put Runtime checking into the Property's set method itself and throw an error if the new value is out of range, but I don't want to throw an error, I just want the PropertyGrid itself to limit the valid range to be 0-10.

Use ICustomTypeDescriptor, PropertyDescriptor and an Attribute.

Create your own Attribute, like RangeAttribute that stores the min and the max. The only thing you have to validate is that the objects that are passed in support ICompareable. It's handy to put in a method in this class to check if a value is within range IsInRange( object val ).

Next create a PropertyDescriptor that takes another PropertyDescriptor as a constructor parameter. In the SetValue method look for the RangeAttribute, call IsInRange(). If it's in range, perform the set (on the PropertyDescriptor that was passed in) if not dont.

Third create a base class (or implement it in all of the classes that you want) that forwards most calls to TypeDescriptor. The only method that you need to implement is GetProperties( Attribute[] ). Basically what you want to do is get a list of all the properties from the reflected class, and create a new PropertyDescriptorCollection with your PropertyDescriptors.

Then you will be able to specify properties like this.

private int _Foo;
[MyRangeAttribute( (int) 0, (int) 10 )]
public int Foo
{
get
{
return _Foo;
}
set
{
if ( value != _Foo )
{
_Foo = value;
}
}
AnswerRe: Can somebody translate this and tell me what it means Pin
led mike30-Oct-08 6:02
led mike30-Oct-08 6:02 
AnswerRe: Can somebody translate this and tell me what it means Pin
Dave Kreskowiak30-Oct-08 6:15
mveDave Kreskowiak30-Oct-08 6:15 
QuestionForcing Usercontrol to forward focus to its current child control Pin
AndrusM30-Oct-08 2:28
AndrusM30-Oct-08 2:28 
QuestionCannot implicitly convert type 'System.DateTime' to 'string' error is rising Pin
Samiullah30-Oct-08 1:20
Samiullah30-Oct-08 1:20 
AnswerRe: Cannot implicitly convert type 'System.DateTime' to 'string' error is rising Pin
TommyTomToms30-Oct-08 1:23
TommyTomToms30-Oct-08 1:23 
AnswerRe: Cannot implicitly convert type 'System.DateTime' to 'string' error is rising Pin
CPallini30-Oct-08 1:28
mveCPallini30-Oct-08 1:28 
GeneralRe: Cannot implicitly convert type 'System.DateTime' to 'string' error is rising Pin
EliottA30-Oct-08 2:17
EliottA30-Oct-08 2:17 
QuestionHow i can connect with MySql Database Pin
wasimsharp30-Oct-08 1:02
wasimsharp30-Oct-08 1:02 
AnswerRe: How i can connect with MySql Database Pin
Sami Sammour30-Oct-08 2:36
Sami Sammour30-Oct-08 2:36 
GeneralRe: How i can connect with MySql Database Pin
wasimsharp30-Oct-08 18:06
wasimsharp30-Oct-08 18:06 
QuestionChecked & unChecked event for tree view using javascript Pin
anithagaraga30-Oct-08 0:20
anithagaraga30-Oct-08 0:20 
AnswerWrongForumException detected... Pin
Mbah Dhaim30-Oct-08 0:34
Mbah Dhaim30-Oct-08 0:34 
AnswerRe: Checked & unChecked event for tree view using javascript Pin
kirri003730-Oct-08 2:51
kirri003730-Oct-08 2:51 
AnswerRe: Checked & unChecked event for tree view using javascript Pin
Paul Conrad30-Oct-08 4:26
professionalPaul Conrad30-Oct-08 4:26 
Question[Message Deleted] Pin
DJ24530-Oct-08 0:18
DJ24530-Oct-08 0:18 
AnswerRe: Changing a datagridview's combobox items based on another combobox Pin
leppie30-Oct-08 0:46
leppie30-Oct-08 0:46 
Questionref parameter Pin
arkiboys29-Oct-08 23:45
arkiboys29-Oct-08 23:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.