locked
combobox.SelectedIndex exception in .NETCF 2.0 RRS feed

  • Question

  • I have created a delegate to programmatically change the selected index of a combobox on a Windows Mobile 5 device, using .NET 2.0, but I still get an exception when I call it.

     

    public delegate void SetIndexComboBoxObservationDelegate(int index);

     

    public void SetIndexComboBoxObservation(int index)

    {

     

    if (!this.comboBoxObservation.InvokeRequired)

    {

     

    comboBoxObservation.SelectedIndex = index;

    }

     

    else

    {

     

    SetIndexComboBoxObservationDelegate setIndexComboBoxObservation = new SetIndexComboBoxObservationDelegate(SetIndexComboBoxObservation);

     

    this.Invoke(setIndexComboBoxObservation);

    }

    }

    The exception returned is System.ArgumentException: ArgumentException at System.Reflection.RuntimeMethodInfo.InternalInvoke() at

    System.Reflection.RuntimeMethodInfo.InternalInvoke()  at

    System.Reflection.RuntimeMethodInfo.InternalInvoke()

    I've put a messagebox into the delegate to print out index when it is called, and it is equal to 1, a valid index.

    Can someone tell me the proper way to programmatically set the SelectedIndex property at runtime, or if this is a known bug of .NETCF 2.0.  I'm forced to use .NETCF 2.0 because I have Visual Studio 2005.

    Don

    Friday, December 16, 2011 10:03 PM

Answers

  • This delegate signature you declared needs an argument. As you're invoking it you do not pass any arguments so that's probably why you're getting an exception. 

    There's another overload of Control.Invoke() which allows you to pass argument array, try it instead.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Don Tucker Monday, December 19, 2011 4:39 PM
    Saturday, December 17, 2011 5:24 AM

All replies

  • This delegate signature you declared needs an argument. As you're invoking it you do not pass any arguments so that's probably why you're getting an exception. 

    There's another overload of Control.Invoke() which allows you to pass argument array, try it instead.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Don Tucker Monday, December 19, 2011 4:39 PM
    Saturday, December 17, 2011 5:24 AM
  • That was totally it.  I'm surprised that my code even compiled.  I changed

    this.Invoke(setIndexComboBoxObservation);

    to

    this.Invoke(setIndexComboBoxObservation, new object[], {index});

    and it worked.  THANK YOU!

    Don

    Monday, December 19, 2011 4:39 PM