Note that there are some explanatory texts on larger screens.

plurals
  1. POMouseDown in WinForm ListBox Kills SelectedIndexChanged
    text
    copied!<p>I'm writing some code to detect toggling of selections in a WindForms ListBox with MultiSelect turned on. Since SelectedIndexChanged only lets me see what is selected after the click, I was looking for a way to detect what was selected before the ListBox was clicked. I implemented the MouseDown event and I can get exactly what I want, but an unfortunate side effect is that I have killed the SelectedIndexChanged event. It will not fire.</p> <p>Is this known behavior? Are there any thoughts about getting to the selection list before the click?</p> <p>Thanks.</p> <p>Edited to include code snippets as requested.</p> <p>Designer generated events:</p> <pre><code>this.lbPhysicianClinic.SelectedIndexChanged += new System.EventHandler( this.lbPhysicianClinic_SelectedIndexChanged ); this.lbPhysicianClinic.MouseDown += new System.Windows.Forms.MouseEventHandler( this.lbPhysicianClinic_MouseDown ); </code></pre> <p>Code snippet showing MouseDown event:</p> <pre><code>private void lbPhysicianClinic_MouseDown( object sender, MouseEventArgs e ) { List&lt;Clinic_List_ByPhysicianResult&gt; Selected = this.PhysicianGetSelectedClinics( this.lbPhysicianClinic.SelectedIndices ); } </code></pre> <p>Code snippet showing SelectedIndexChanged event:</p> <pre><code>private void lbPhysicianClinic_SelectedIndexChanged( object sender, EventArgs e ) { try { if ( this.FormInitComplete &amp;&amp; this.RefreshUIComplete ) { List&lt;Clinic_List_ByPhysicianResult&gt; Selected = this.PhysicianGetSelectedClinics( this.lbPhysicianClinic.SelectedIndices ); Clinic_List_ByPhysicianResult DroppedClinic = new Clinic_List_ByPhysicianResult(); </code></pre> <p>I set a breakpoint in each event and if the MouseDown event is there, the SelectedIndexChanged event never fires. It only fires when the MouseDown event is gone.</p> <p>Hopefully this clarifies things.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload