473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 6099
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

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

Similar topics

6
by: Richard | last post by:
Hi. I use a ListView to display data in tabular form. Each ListView row corresponds to a data record. The ListView Item of the record is the record key or code. Each SubItem in that row...
0
by: suz | last post by:
Hey, I have a collection with custom objects. That collection is bounded to a listview (I used the article of Lhotka). The listview is also sortable. I have also textboxes bound to the same...
2
by: Michael C | last post by:
Hi all, When I try to use the GetItemAt (e.X, e.Y) method in a ListView MouseDown() event, it only works some of the time. If I right-click on an open area of the ListView, I get null back as...
13
by: Maheshkumar.R | last post by:
hi groups, I have placed an listview control, i want to iterate thru the control and find the clicked event items. listView2.Items.Add(fname.ToString(), i); how i can perform the iteration...
6
by: Nick | last post by:
Hi there, I'm trying to implement drag-drop for my listview control in large icon view mode. Unfortunately the order of the items gets completely messed up upon inserting the item back into the...
5
by: Martin Horn | last post by:
Hi all, I want to implement a listview with editable subitems and I assume the easiest way is to overlay a textbox over the item to be edited. With this in mind I have come up with: Using...
0
by: Droopy | last post by:
Hi, I got the System.ArgumentOutOfRangeException exception when adding an item in ListView. This ListView (listViewOutput) is used to display messages to user (normal messages and error...
4
by: Archimed | last post by:
Hi, I try to use an ImageList with a ListView but that don't work. I make a ListView in VirtualMode with LargeIcon view. I put the ImageList in the LargeImageList property. I add a bitmap...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.