ListView.View = Details with many columns and many items causing vertical
scrollbar to appear. No horizontal scrollbar and visible items at any
time<=10.
I cannot find an event to catch when the user scrolls the scrollbar? The
goal is to detect when the listview is scrolled and then get all visible
items (or just the top one and work my way down since I know how many can be
visible at a time) and do some function...
I could overlay the listview's scrollbar with an VScrollBar and then call
EnsureVisible to do my own scrolling but there has to be a better way.
Any ideas?
Cheers
Daniel
Could be wrapped in a control of course...
Cheers
Daniel
//---------- start code
//1. Throw a ListView on a form... change its View to details, add columns
and items....
//2. run it in emulator/device to see how many items are fully visible at
run time...
//3. Throw a vScrollBar on the form and in the Form load event put this
code:
private void Form1_Load(object sender, System.EventArgs e) {
vScrollBar1.Minimum = 0;
vScrollBar1.Maximum = listView1.Items.Count-1;
vScrollBar1.SmallChange = 1;
vScrollBar1.LargeChange = maxNoOfVisibleItems;
vScrollBar1.Height = listView1.Height;
vScrollBar1.Left = listView1.Left + listView1.Width - 20;
vScrollBar1.Top = listView1.Top;
vScrollBar1.Width = 20;
vScrollBar1.BringToFront();
}
//4. Add an eventhandler for scrollbar's ValueChanged and put this code:
private void vScrollBar1_ValueChanged(object sender, System.EventArgs e) {
int toScroll;
if (vScrollBar1.Value > topMostItem){ // Going down
toScroll = vScrollBar1.Value + maxNoOfVisibleItems - 1;
}else{ // Going up
toScroll = vScrollBar1.Value;
if (toScroll > listView1.Items.Count - maxNoOfVisibleItems){
toScroll = listView1.Items.Count - maxNoOfVisibleItems;
}
}
// Do the scroll
listView1.EnsureVisible(toScroll);
// Update TopMost index
topMostItem = vScrollBar1.Value;
}
//5. Declare in your form the following 2 members
private int maxNoOfVisibleItems = 10; //Change this
private int topMostItem = 0; //index
//---------- end code
"Daniel Moth" <dmo...@hotmail.com> wrote in message
news:evblkwv7...@TK2MSFTNGP10.phx.gbl...