Setting FocusedItem in ListView ( C# )

  • Thread starter Thread starter Abdolhosein Vakilzadeh Ebrahimi
  • Start date Start date
A

Abdolhosein Vakilzadeh Ebrahimi

Hi:

I would like to make sure listview top item is the current item and
has focus reticle, after scrolling.

But the FocuedItem is readonly and using SelectedIndices or selecting
item using selected property has no effect.

Thanks
A.V.Ebrahimi
vakilzadeh(AT)kzlabs.com
 
Below is a custom ListView that will automatically select, and set focus to,
the first visible item in the list after scrolling. It may not be exactly
what you want but it should get you going in the right direction.

public class ListViewEx : System.Windows.Forms.ListView
{
public ListViewEx()
{
this.HideSelection = false;
this.MultiSelect = false;
}

private const int WM_VSCROLL = 0x0115;

protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_VSCROLL:
{
this.TopItem.Focused = true;
this.TopItem.Selected = true;
this.Focus();
break;
}
}
base.WndProc(ref m);
}
}
 
Back
Top