I often have a situation where within the SelecteIndexChanged event of a
ComboBox, I want to change the index again. For example, a changed index
triggers an action that can fail, in which case I want to return the index of
the combobox to its previous value. However, doing this within the event
handler of course triggers another invocation of the event handler. Is there
a standard idiom for handling this? I mean other than temporarily disabling
the event handler, which seems pretty kludgey. Thanks.
Maqsood Ahmed - 04 Aug 2005 07:34 GMT
Hello,
You can control the behavior using a boolean value something like
bInternal...
private void ComboBoxSelectedIndexChanged(object sender,EventArgs e)
{
if(!this.bInternal)
{
try
{
this.bInternal = true;
//Manipulate the values here.
}
catch
{
//Error Handling, logging etc.
}
finally
{
this.bInternal = false;
}
}
}
HTH. Cheers :)
Maqsood Ahmed [MCP C#,SQL Server]
Kolachi Advanced Technologies
http://www.kolachi.net
pearsons_11114 - 04 Aug 2005 08:12 GMT
Hmm...it's actually simpler just to disable/enable the handler. But I like
this for a more general approach to preventing recursion. Thanks!
> Hello,
> You can control the behavior using a boolean value something like
[quoted text clipped - 27 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***