473,785 Members | 2,282 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 6176
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
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10097
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
8983
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
7505
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
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
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...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
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.