winforms - SelectedIndexChanged called before class constructor in c# -


i create class in c# application called acquisti. initialize in form constructor , call method of class in combobox selectedindexchanged event. problem when run program error says object of acquisti class created null. means selectedindexchanged event called before form constructor, isn't it? tried selectedvaluechanged event have same problem. here simple code:

acquisti _acquisti;      public form1()     {         initializecomponent();         windowstate = formwindowstate.maximized;          (int = datetime.now.year; >= 2000; i--)             annoacquisti.items.add(i);          annoacquisti.selectedindex = 0;          _acquisti = new acquisti();     }        private void annoacquisti_selectedindexchanged(object sender, eventargs e)     {         _acquisti.load(ref acquistidgv, annoacquisti.selecteditem.tostring());     } 

selecteindexchanged called due line:

annoacquisti.selectedindex = 0; 

and initializing _acquisti after that. can move line before like:

public form1() {     initializecomponent();     _acquisti = new acquisti(); //move here     windowstate = formwindowstate.maximized;      (int = datetime.now.year; >= 2000; i--)         annoacquisti.items.add(i);      annoacquisti.selectedindex = 0;  } 

since control moves selectedindexchanged event , @ point _acquisti still null, why exception.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -