Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select combo box value

Status
Not open for further replies.

Saturn57

Programmer
Aug 30, 2007
275
CA
I have a combo box that is attached to a database. And the possible selections come from a custom list. I also have a case statement that runs based on the value in the combo box. I have no problem using the case statement when the form is first used and the combo box is used for a selection for the first time but if I were to close this form and open the same record where the previous combo box selection is shown without having to reselect then the case statement will not work. The case statement does not work until I reselect from the combo box list.

my case statement is as follows:

switch (myvalTB.Text)
{
case "metric"......


 
Maybe you could have a Form_Enter() handler that then calls the method in which your switch{} statements resides? and passes in the selected combo box value?

Code:
private void SwitchIt(string sValue){

   switch {
      case ... 
      // etc 
   }

}

private void Form_Enter(object sender, EventArgs e){
  
   SwitchIt(comboName.SelectedText);
   // can't think of the proper command to get the text
   // of the top of my head, but should point you in the
   // right direction!
}

Regards,

Martin

Computing Design And Services:
 
MJB3K not sure I understand. What does the Form_Enter portion do?
 
it gets called when you enter the form. like if you close the form or reopen it.

try putting a messagebox in the event and you'll see when it gets called, if its not the one you want then try others.

Im not 100% sure if thats quite the event you need, you could try Form_Load() or other form events till you get the desired result...

Regards,

Martin

Computing Design And Services:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top