validating ListView lines

Hi,

We have a form with a ListView control and a number or editboxes
corresponding to the ListView's columns. When the user selects a line,
values of columns for that line are copied into the editboxes and the user
can type stuff in. When user changes line selection in the listview, the
editboxes must be checked to contain valid data and if so, the listview line
that loses selection must be updated first. If the data are not valid, we
should display an error message and not allow changing of the selected line.
I couldn't find any event occuring when the selection change is initiated
but prior to the actual change. Is there any possibility to prevent
selection changing if certain conditions are met?
What I did is have the last selected line index stored in a member
variable, handle SelectedIndexChanged and in case of error send the
selection back. However, I'm experiencing some difficulties with this
approach, as my handler gets called too many times for my taste. Normally,
for every selection changing, the handler is called twice, once with the
selected lines list empty and once with the list containing the new index (I
get the selection list within the handler and the multiselect property is
false). In my case, assuming the user has entered some wrong values
corresponding to line 1 and changes selection to line 2, the first pair of
handler calls is with selection on line 2, then, after I change the
selection back (programatically), another pair is with line 1 selected , and
then, unexpectedly, there is another pair of calls with the selection on
line 2 though the selection bar stays on line 1 where I set it. Any idea why
is that? It bothers me because the editboxes are again checked for errors
and the message displayed.

Thanks in advance for any suggestion,
[1925 byte] By [KwayZee] at [2007-11-17 17:09:16]