0

I have a long ListView which contains a list of actions which my app is currently running (each action at a time). Upon running each action, the relevant ListViewItem is bolded. The ListView is long so I have vertical scroll bar.

My question is how to make the current running action shown to the user, meaning, how do I "scroll" the list view to that item.

I tried to manually select the row ==> didn't work. I've used ListViewItem.EnsureVisible but that made the ListView flicker on each change.

Any idea? Thanks.

Edited: I've added some code, even though the code is pretty simple. Whenever a new action is running, I run the following:

foreach (ListViewItem item in m_ListView.Items)
{
    FontStyle style = ((index == value) ? FontStyle.Bold : FontStyle.Regular);
    item.Font = new Font(item.Font, style);

    if (index == value)
    {                        
         m_ModulesListView.EnsureVisible(index);
    }

    index++;
}
Lior Ohana
  • 3,467
  • 4
  • 34
  • 49
  • Hi, please show some code especially the way you call EnsureVisible... that should be the preferred solution, about flickering it could depend on the way you call it and what you do with the control. – Davide Piras Aug 24 '11 at 06:04

3 Answers3

2

You means

listView1.EnsureVisible(listView1.Items.Count - 1);
shenhengbin
  • 4,236
  • 1
  • 24
  • 33
  • I did mean ListViewItem.EnsureVisible which does the same as ListView.EnsureVisible (I didn't mean static function if that what you think)...ofcourse it goes on a ListViewItem instance. Anyway, doing the same on the ListView gave the same result...the ListView flickers on each change. – Lior Ohana Aug 24 '11 at 06:18
2

Maybe you should call ListView.BeginUpdate() before your loop and ListView.EndUpdate() after your loop.

Oliver
  • 43,366
  • 8
  • 94
  • 151
0

Found a nice solution. It involves using win32 but it does the job. Apparently, it is possible to set double buffering on the list which solves the flickering problem. So, using EnsureVisible with the double buffering work just fine.

Community
  • 1
  • 1
Lior Ohana
  • 3,467
  • 4
  • 34
  • 49