Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

ComboBox exception - Index 0 does not have a value

$
0
0

I  am getting an exception on this line of code

       object current = comboBoxFunction.SelectedValue;

The runtime exception is

Index 0 does not have a value.
   at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
   at System.Windows.Forms.ListControl.get_SelectedValue()

The problem is that this is hard to duplicate, I've stepped through the code where SelectedValue is null and that doesn't cause any problems.  The ComboBox is being databound.

During initialization I do this

   comboBoxFunction.Items.Clear();
   comboBoxFunction.DataSource = functions;
   comboBoxFunction.ValueMember = "Value";
   comboBoxFunction.DisplayMember = "DisplayName";
   comboBoxFunction.SelectedIndex = 0;

After initialization that is when the line that gets the exception is executed

object current = comboBoxFunction.SelectedValue;

Any ideas as to what this error means and how I can duplicate it?  Thanks


Viewing all articles
Browse latest Browse all 12583


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>