Home > Net > Newbie questions: c # Winform, change the selected radio button option, the display InvalidArgument=
Newbie questions: c # Winform, change the selected radio button option, the display InvalidArgument=
Time:10-07
From the point of spending to income, the pop-up error above
Private void rdoExpenditure_CheckedChanged (object sender, EventArgs e) { CboCatogory. Items. The Clear (); If (rdoExpenditure. Checked==true) { CboCatogory. Items. The Add (" cost of living "); CboCatogory. Items. The Add (" fixed assets "); CboCatogory. Items. The Add (" entertainment "); } The else { CboCatogory. Items. The Add (" work income "); CboCatogory. Items. The Add (" investment "); CboCatogory. Items. The Add (" other income "); } CboCatogory. SelectedIndex=0; }
CboCatogory category of the combo box is payments, specific Item is determined by the balance of payments types, code like the book, don't know why will go wrong, the great god, please give directions, thank you.
CodePudding user response:
If (rdoExpenditure. Checked==true) { CboCatogory. Items. The Add (" cost of living "); CboCatogory. Items. The Add (" fixed assets "); CboCatogory. Items. The Add (" entertainment "); } The else { CboCatogory. Items. The Add (" work income "); CboCatogory. Items. The Add (" investment "); CboCatogory. Items. The Add (" other income "); } CboCatogory. SelectedIndex=0;
Try this way
CodePudding user response:
You check whether there is SelectedIndexChange cboCatogory events, cboCatogory. Items. The Clear () the trigger SelectedIndexChange events, while SelectedIndexChange event. If you have the code to use cboCatogory Items [0] will throw an exception (for all Items Clear off, no item index of 0).