-1

I have a ListBox control with IntegerUpDown in each ListBoxItem. Everything works fine, but when the IntegerUpDown reaches the min or the max I set, If I click on the disabled arrows it'll trigger a selectionchanged event for the listbox. Disabled arrow

private void lbItem_SelectionChanged(Object sender, SelectionChangedEventArgs e)
{    
     if (//e.source != integerupdowncontrol)
         //update other view, etc.  
}
sponge
  • 31
  • 4

1 Answers1

0

Have you tried hooking into the selectionchanged event, checking for your disabled condition, and if disabled set the SelectionChangedEventArgs.Handled to true?

SelectionChangedEventArgs MSDN

private void OnSelectionChanged(Object sender, SelectionChangedEventArgs args){
      if(/*My min or max has been reached*/){
            args.Handled = true;
            return;
      }
}

Here is another example with keypressed

DotNetRussell
  • 9,716
  • 10
  • 56
  • 111
  • How would I check if the selectionchanged event came from the IntegerUpDown control though? Both Source and OriginalSource are pointing to listbox. Unless I know the event originated from the IntegerUpDown I can't handle it. – sponge Jun 29 '16 at 14:54
  • Well unless you post your code I can't really provide any further details @sponge – DotNetRussell Jun 29 '16 at 14:55
  • I fixed the issue by adding a MouseLeftButtonDown event for the IntegerUpDown in which I set Handled = true. It feels "hackish" though. – sponge Jun 29 '16 at 15:05