1
votes

When I set comboBoxEdit.selectedindex = some value, it never take this value. its value is always -1. I have set it in Constructor or in Form_Load.

if (oPersclientEntrp.TypPrint == 1) {
  comboBoxEdit_Print.SelectedIndex = 0;
} else {
  comboBoxEdit_Print.SelectedIndex = 2;
}

I have heard that The SelectedValue, SelectedIndex, SelectedItem properties can't be set until the control is added to the form. After the control is added to the form, the selectedValue, -Index and -Item properties can be set.

but I bind the value on design mode design mode.

2
are you using DevExpress Controls??Niranjan Singh

2 Answers

2
votes

Try updating your code to be this:

if (oPersclientEntrp.TypPrint == 1) { comboBoxEdit_Print.SelectedIndex = 0; }
else { comboBoxEdit_Print.SelectedIndex = 1; }

If you only have 2 items, your SelectIndex should be 1, not 2.

0
votes

You have 2 Items and the index of SelectedIndex starts with 0 (Because it access' an internal array, which of course starts with 0). So you have to edit your code to use index 0 instead of 1 and index 1 inseatd of 2.

Btw, this is a common behavior of the most SelectedIndex properties, i.e. of TabControl.