I've got a listview on a form in report style. It's populated with 40
items. I want to prevent the user clicking on some items, and if the
user clicks on one of these items I want the selection to revert back
to the old selection, hideselection property if false, listview is
single select.

In the OnSelectedChange() handler I test to see if the newly selected
item is a selectable one, if it's not, I try to change the selection
like so.

private void OnSelectedItemChanged(object sender, System.EventArgs e)
{
if( listView1.SelectedItems.Count != 0 )
{
int idx = listView1.SelectedItems[0].Index;
bool ret = execScript.isExecutable(idx);
if(ret == false)
{
listView1.Items[execScript.getCurrentExecNum()].Selected = true;
listView1.Select();
listView1.EnsureVisible(execScript.getCurrentExecNum());
listView1.Focus();
}
}

This doesn't work.
Neither does posting a user message to this function by overriding the
WndProc and calling Win32

[DllImport("user32.Dll")]
public static extern Int32 PostMessage(IntPtr Handle, Int32
ConnectionType, IntPtr wParam, IntPtr lParam);

ResetSelection()
{
listView1.Items[execScript.getCurrentExecNum()].Selected = true;
listView1.Select();
listView1.EnsureVisible(execScript.getCurrentExecNum());
listView1.Focus();
}

Neither does using a delegate like this

listView1.BeginInvoke(new
OnSelectedItemChangedDelegate(ResetSelection),null);

Neither does adding a filter on to the listview control and trapping
the LVN_ITEMCHANGING or LVN_ITEMCHANGED message in the WM_NOTIFY.

Interesting to note though if I add a button to the form and call my
ResetSelection() function it works fine.

Three days I've spent on this. Can anyone help?

Thanks

Youngie...