I have a DropDownList
in a project. This DropDownList
contains a SelectedIndexChanged
event:
private void cbo_SelectedIndexChanged(object sender, EventArgs e){......}
Is it possible to check if the index was changed in the code, like:
cbo.SelectedIndex = placering;
, or if the change happened by user interaction?
Since DropDownList doesn't have property Focused
as it is for ComboBox
control in WinForms
it's not that easy. One way is to add custom flag, and change its value before changing the SelectedIndex
property. Inside of event handler you can check for this flag and reset its value :
private volatile bool isAutoFired = false;
Then somewhere in code :
isAutoFired = true;
cbo.SelectedIndex = placering;
private void cbo_SelectedIndexChanged(object sender, EventArgs e)
{
if(!isAutoFired)
{
// event is fired by user
}
isAutoFired = false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With