473,770 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

listView messages – how to set listviewItem position - LVM_SETITEMPOSI TION??

2 New Member
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_SETITEMPOSI TION 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.S endMessage from Microsoft.Windo wsCE.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 6175
VoraAnkit
1 New Member
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 New Member
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
2334
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 represents a field from the record. I implemented a context menu so the user can "Copy" the cell content to the clipboard with this code:
0
3036
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 collection. When SelectedIndexChanged fires on the listview, I have to set the position of the currencymanager so the textboxes
2
11660
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 expected. If I right-click on a ListViewItem, I get that ListViewItem back. But then... if I right-click on an open area of the ListView again I get the last ListViewItem I clicked on back... I'm sure there's a way around this. GetItemAt...
13
3771
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 to find the item clicked...? and its item. thankz-- Mähésh Kumär. R
6
3420
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 listview, removing the item obviously keeps everything fine but the second I use insert the item is added to the *end* of the listview. Does anyone have any tips on how I can solve this issue?? Call Items.Remove(SourceItem)
5
2374
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 fullrowselect=true in the listview Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, _
0
3143
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 messages): private void AddOutputMessage (string message) { listViewOutput.BeginUpdate ();
4
14484
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 to the ImageList When i want to see the item "icon" with the imagelist imageindex
2
6831
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 form every thing works fine: checking items by code
0
9453
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10036
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8929
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.