468,740 Members | 1,947 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,740 developers. It's quick & easy.

listView messages how to set listviewItem position - LVM_SETITEMPOSITION??

2
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.         }
Apr 3 '09 #1
2 5641
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. }
Apr 11 '09 #2
witpo
2
Hi,
Thank you, it seem that I should send message after
listView.Items.Add(item);.
Apr 12 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by suz | last post: by
2 posts views Thread by Michael C | last post: by
13 posts views Thread by Maheshkumar.R | last post: by
6 posts views Thread by Nick | last post: by
5 posts views Thread by Martin Horn | last post: by
4 posts views Thread by Archimed | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.