• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

.NET - Who checked my checkbox?!

SoftwareEng

Senior member
Hi -

In .NET, I have code that checks a check box (chkBlah.Checked = true). Of course, that triggers the Checked event handler. The event handler is also triggered when the USER checks that check box.

What's the easiest way to find out who checked that box - my code or the user? If there a "originator" property to tell me why the event was fired?

C#/VB.NET

Thanks guys
 
bool softwareCheckedTheBoxByItself = false;

...

softwareCheckedTheBoxByItself = true;
chkBlah.checked = true;

eventHandler(){
if(softwareCheckedTheBoxByItself){
Console.writeln("I did this"!);
}
else{
Console.writeln("You did this!");
}
softwareCheckedTheBoxByItself = false;
}
 
Thanks, this works. But I was hoping for some built-in magicalproperty, e.g. .ChangedByuser 🙂

Oh well, maybe in .NET 3.0

Originally posted by: notfred
bool softwareCheckedTheBoxByItself = false;

...

softwareCheckedTheBoxByItself = true;
chkBlah.checked = true;

eventHandler(){
if(softwareCheckedTheBoxByItself){
Console.writeln("I did this"!);
}
else{
Console.writeln("You did this!");
}
softwareCheckedTheBoxByItself = false;
}

 
Originally posted by: SoftwareEng
Thanks, this works. But I was hoping for some built-in magicalproperty, e.g. .ChangedByuser 🙂

Oh well, maybe in .NET 3.0

Originally posted by: notfred
bool softwareCheckedTheBoxByItself = false;

...

softwareCheckedTheBoxByItself = true;
chkBlah.checked = true;

eventHandler(){
if(softwareCheckedTheBoxByItself){
Console.writeln("I did this"!);
}
else{
Console.writeln("You did this!");
}
softwareCheckedTheBoxByItself = false;
}


Not the best way to do it, since you'd need a global scoped variable for each checkbox.

I'm sure there are other better way's, but i'd recommend removing/adding the eventhandler when you do it programtically...

 
I'm sure you could write your own or subclass CheckBox to accomplish this without too much trouble.

Originally posted by: WannaFly
Not the best way to do it, since you'd need a global scoped variable for each checkbox.
It would not have to be global, just the same scope as the check box itself, which is usually private. So long as your event handler is local anyway.
 
Just use the Sender object that is passed in. That is what it is there for.

Edit: Sorry, I guess that wont work. Read the guy two above. He's got it.
 
Back
Top