How can I prevent selectedValue from changing when the tableAdapter Fill () method is called?
I have bound my ListBox to some data.
The problem is when I call the myTableAdapter.Fill (..) method, the SelectedValue changes whatever is the first ID of the item in the list. Although the "Selected Value" in VS is not anchored anywhere (see image). alt text http://img370.imageshack.us/img370/2548/ss20090108212745qz2.png
How can I prevent this behavior please?
Many thanks for the help.
0
source to share
2 answers
The easiest way I can think of is to change the fill code of the table adapter to something like this:
string preSelected = myDropDownList.SelectedValue;
myTableAdapter.Fill(myDataTable);
myDropDownList.SelectedValue = preSelected;
You will have a problem if the item no longer exists, so you can add a condition to check for this.
+1
source to share