Connecting Tech Pros Worldwide Forums | Help | Site Map

listView messages – how to set listviewItem position - LVM_SETITEMPOSITION??

Newbie
 
Join Date: Apr 2009
Posts: 2
#1: Apr 3 '09
Hi,
I would like to display all listview items in one row with scroll bar below it – instead of multiple rows and scroll bar on the right. Someone told me that I can achieve it using LVM_SETITEMPOSITION message.
According to my knowledge code below should set position for each item added to listView control. There are two ways of doing it - we can use MessageWindow.SendMessage from Microsoft.WindowsCE.Forms or use DllImport and SendMessage. For some unknown reason code is not working as expected and control displays items in multiple rows.
Could someone please help me ?

Expand|Select|Wrap|Line Numbers
  1. public static IntPtr MakeLParam(int wLow, int wHigh)
  2.         {
  3.             return (IntPtr)(((short)wHigh << 16) | (wLow & 0xffff));
  4.         }
  5.  
  6.  
  7.         [DllImport("coredll.dll", SetLastError = true)]
  8.         public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  9.  
  10.         const uint LVM_SETITEMPOSITION = 0x1000 + 15;
  11.  
  12.         private void function()
  13.         {
  14.  
  15.             ImageList imageList = new ImageList();
  16.             listView.View = System.Windows.Forms.View.LargeIcon;
  17.  
  18.  
  19.  
  20.             try
  21.             {
  22.  
  23.                 int x = 0;
  24.                 foreach ()
  25.                 {
  26.  
  27.                     ListViewItem item = new ListViewItem(desc);
  28.  
  29.  
  30.                     //magic
  31.                     int index = listView.Items.Count;
  32.  
  33.  
  34.  
  35.                     IntPtr wparam = (IntPtr)index;
  36.                     IntPtr lparam = MakeLParam(x, 0);
  37.  
  38.                     Message mes = Message.Create(listView.Handle, 0x1000 + 15, wparam, lparam);
  39.                     MessageWindow.SendMessage(ref mes);
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.                     //old
  48.                     //IntPtr listH = listView.Handle;
  49.                     //int index = listView.Items.Count;
  50.  
  51.  
  52.                     //int y = 0;
  53.  
  54.                     //int t = SendMessage(listH, LVM_SETITEMPOSITION, index, m);
  55.                     //IntPtr t = SendMessage(listView.Handle, LVM_SETITEMPOSITION, (IntPtr)index, MakeLParam(x, y));
  56.  
  57.                     x += 20;
  58.  
  59.                     listView.Items.Add(item);
  60.  
  61.                 }
  62.  
  63.                 listView.LargeImageList = imageList;
  64.  
  65.             }
  66.             catch (Exception ex)
  67.             {
  68.  
  69.             }
  70.         }

Newbie
 
Join Date: Apr 2009
Posts: 2
#2: Apr 11 '09

re: listView messages – how to set listviewItem position - LVM_SETITEMPOSITION??


Expand|Select|Wrap|Line Numbers
  1. public static IntPtr MakeLParam(int wLow, int wHigh)
  2. {
  3. return (IntPtr)(((short)wHigh << 16) | (wLow & 0xffff));
  4. }
  5.  
  6.  
  7. [DllImport("coredll.dll", SetLastError = true)]
  8. public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  9.  
  10. const uint LVM_SETITEMPOSITION = 0x1000 + 15;
  11.  
  12. private void function()
  13. {
  14.  
  15. ImageList imageList = new ImageList();
  16. listView.View = System.Windows.Forms.View.LargeIcon;
  17.  
  18.  
  19.  
  20. try
  21. {
  22.  
  23. int x = 0;
  24. foreach ()
  25. {
  26.  
  27. ListViewItem item = new ListViewItem(desc);
  28.  
  29.  
  30. //magic
  31. int index = listView.Items.Count;
  32.  
  33.  
  34.  
  35. IntPtr wparam = (IntPtr)index;
  36. IntPtr lparam = MakeLParam(x, 0);
  37.  
  38. Message mes = Message.Create(listView.Handle, 0x1000 + 15, wparam, lparam);
  39. MessageWindow.SendMessage(ref mes);
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. //old
  48. //IntPtr listH = listView.Handle;
  49. //int index = listView.Items.Count;
  50.  
  51.  
  52. //int y = 0;
  53.  
  54. //int t = SendMessage(listH, LVM_SETITEMPOSITION, index, m);
  55. //IntPtr t = SendMessage(listView.Handle, LVM_SETITEMPOSITION, (IntPtr)index, MakeLParam(x, y));
  56.  
  57. x += 20;
  58.  
  59. listView.Items.Add(item);
  60.  
  61. }
  62.  
  63. listView.LargeImageList = imageList;
  64.  
  65. }
  66. catch (Exception ex)
  67. {
  68.  
  69. }
  70. }
Newbie
 
Join Date: Apr 2009
Posts: 2
#3: Apr 12 '09

re: listView messages – how to set listviewItem position - LVM_SETITEMPOSITION??


Hi,
Thank you, it seem that I should send message after
listView.Items.Add(item);.
Reply

Tags
listview messages, listviewitem position, lvm_setitemposition