tags:

views:

420

answers:

2

Hi Freinds,

I have a ComboBox that have a list of EmpolyeeNames. When a user selects a EmpolyeeName "e1", a ListBox below gets populated with data for the chosen employee. That data can be modified. The user and has to press the Save button after all changes are done.

But if the user forgets to press Save and select another employee from the ComboBox say "e2" , here i ask user mEssagebox "Do you want to save data for employee "e1" if yes then I save the data of particular employee "e1",

But here while saving the data combo box index gets changed and its text show recently selected employee "e2", but the data is of employee "e1".

HOw can i retain the old previous text of employye "e1" in comboBox until save gets completed.??

+3  A: 

Quite simply, when the combobox item is selected put the employee into a class variable. Use this class variable instead of the item in the combobox.

After you have saved (or prompted) the user you can then set the variable to the newly selected item.

rein
+1  A: 

Your focus here should really be on how you are going to detect when the user has changed data in the listbox. You could put a flag somewhere that will be an indicator whether some data has been changed for that particular user. If for example it is the text that will change in the listbox item you could use the TextChanged event to set the flag.

Example:

bool employeeEdited = false;

private ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
     if (employeeEdited)
     {
         // prompt user to save
     }
     // reset flag
     employeeEdited = false;
}

private void ListBox1_TextChanged(object sender, EventArgs e)
{
     employeeEdited = true;
}
James
james,Im having one common function -CheckandSaveChanges().in -CheckandSaveChanges() only i handle the prompt and any modification ..and if there any changes..i save through a background worker.i calles CheckandSaveChanges function on selectedIndexChange of combobox,however the text in combobox sets to recent selected not the previous text of employee1.
Andy
You will have to refresh the listbox i.e. repopulate it if the user decides not to save the changes. Or you could just do the refresh after the CheckAndSaveChanges method because regardless the correct information will appear anyway as you would have saved the new information at this point.
James