Guest User

Untitled

a guest
May 21st, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. private void WatchTopItemChanged(ListView listView, Action callOnChanged) {
  2. var lastTopItem = listView.TopItem;
  3. listView.DrawItem += delegate {
  4. if (lastTopItem != listView.TopItem) {
  5. lastTopItem = listView.TopItem;
  6. callOnChanged();
  7. }
  8. };
  9. }
  10.  
  11. using System;
  12. using System.Windows.Forms;
  13. using System.Runtime.InteropServices;
  14.  
  15. class MyListView : ListView {
  16. public event EventHandler TopItemChanged;
  17.  
  18. protected virtual void OnTopItemChanged(EventArgs e) {
  19. var handler = TopItemChanged;
  20. if (handler != null) handler(this, e);
  21. }
  22.  
  23. protected override void WndProc(ref Message m) {
  24. // Trap LVN_ENDSCROLL, delivered with a WM_REFLECT + WM_NOTIFY message
  25. if (m.Msg == 0x204e) {
  26. var notify = (NMHDR)Marshal.PtrToStructure(m.LParam, typeof(NMHDR));
  27. if (notify.code == -181 && !this.TopItem.Equals(lastTopItem)) {
  28. OnTopItemChanged(EventArgs.Empty);
  29. lastTopItem = this.TopItem;
  30. }
  31. }
  32. base.WndProc(ref m);
  33. }
  34.  
  35. private ListViewItem lastTopItem = null;
  36. private struct NMHDR {
  37. public IntPtr hwndFrom;
  38. public IntPtr idFrom;
  39. public int code;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment