I would like to provide the user with the ability to cancel the=
change of an index in a ListView (for instance if there is data=
that has changed related to the ListView, etc=2E)=2E=2E=2Eand I have=
been able to get the code shown below to do this, but everytime=
the user indicates that he/she would like to revert to the=
original selection they get prompted a second time and have to=
indicate so again before the process will successfully=
complete=2E

Now=2E=2E=2EI am aware of the fact that the SelectedIndexChanged event=
gets called twice when the index changes - I have tried to=
handle that by checking for the number of SelectedIndices=2E I=
have also added a user defined variable ("ListInitialized") that=
causes code in the SelectedIndexChanged event handler to be=
skipped when set to false=2E

A few notes about the code=2E listView1 is a simple ListView with=
two items in the collection each of which has one sub-item=
(names or contents of items and sub-items can be anything you=
want)=2E Multi-select is set to false (I am only dealing with one=
selected item at a time here)=2E HideSelection is set to false=
(because I am allowing the user to edit other fields and always=
want the selection displayed)=2E View is set to "details" (so I=
can see the sub-items)=2E FullRowSelect is set to true (each item=
is treated as a single entry)=2E

Can anyone tell me what is happening here? How can I get this=
code to work so that a user can cancel his/her entry without=
having to go through the cancellation process twice?

Thanks in advance=2E

lwc


=09=09private void listView1_SelectedIndexChanged(object sender,=
System=2EEventArgs e)
=09=09{
=09=09=09if (listView1=2ESelectedIndices=2ECount > 0 &&=
this=2EListInitialized)
=09=09=09{
=09=09=09=09if (MessageBox=2EShow("Revert to original selection?","What=
now?",MessageBoxButtons=2EYesNo) =3D=3D DialogResult=2EYes)
=09=09=09=09{
=09=09=09=09=09this=2ERevertToOriginalSelection();
=09=09=09=09}
=09=09=09=09else
=09=09=09=09{
=09=09=09=09=09this=2ESelectedValue =3D listView1=2ESelectedItems[0]=2EText;
=09=09=09=09}
=09=09=09}
=09=09}

=09=09private void RevertToOriginalSelection()
=09=09{
=09=09=09this=2ElistView1=2ESelectedItems=2EClear();

=09=09=09int i;
=09=09=09ListViewItem lvi;
=09=09=09for (i=3D0;i<listView1=2EItems=2ECount;i++)
=09=09=09{
=09=09=09=09lvi =3D listView1=2EItems[i];
=09=09=09=09if (lvi=2EText =3D=3D this=2ESelectedValue)
=09=09=09=09{
=09=09=09=09=09MessageBox=2EShow("before selecting original value");
=09=09=09=09=09this=2EListInitialized =3D false;
=09=09=09=09=09lvi=2ESelected =3D true;
=09=09=09=09=09this=2EListInitialized =3D true;
=09=09=09=09=09MessageBox=2EShow("after selecting original value");
=09=09=09=09=09return;
=09=09=09=09}
=09=09=09}
=09=09}
--------------------------------
From: lwc

-----------------------
Posted by a user from =2ENET 247 (http://www=2Edotnet247=2Ecom/)

<Id>TeOjPRkgDESkz5l6ElT1dg=3D=3D</Id>