listView messages – how to set listviewItem position - LVM_SETITEMPOSITION?? | Newbie | | Join Date: Apr 2009
Posts: 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 ? - public static IntPtr MakeLParam(int wLow, int wHigh)
-
{
-
return (IntPtr)(((short)wHigh << 16) | (wLow & 0xffff));
-
}
-
-
-
[DllImport("coredll.dll", SetLastError = true)]
-
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
-
-
const uint LVM_SETITEMPOSITION = 0x1000 + 15;
-
-
private void function()
-
{
-
-
ImageList imageList = new ImageList();
-
listView.View = System.Windows.Forms.View.LargeIcon;
-
-
-
-
try
-
{
-
-
int x = 0;
-
foreach ()
-
{
-
-
ListViewItem item = new ListViewItem(desc);
-
-
-
//magic
-
int index = listView.Items.Count;
-
-
-
-
IntPtr wparam = (IntPtr)index;
-
IntPtr lparam = MakeLParam(x, 0);
-
-
Message mes = Message.Create(listView.Handle, 0x1000 + 15, wparam, lparam);
-
MessageWindow.SendMessage(ref mes);
-
-
-
-
-
-
-
-
//old
-
//IntPtr listH = listView.Handle;
-
//int index = listView.Items.Count;
-
-
-
//int y = 0;
-
-
//int t = SendMessage(listH, LVM_SETITEMPOSITION, index, m);
-
//IntPtr t = SendMessage(listView.Handle, LVM_SETITEMPOSITION, (IntPtr)index, MakeLParam(x, y));
-
-
x += 20;
-
-
listView.Items.Add(item);
-
-
}
-
-
listView.LargeImageList = imageList;
-
-
}
-
catch (Exception ex)
-
{
-
-
}
-
}
| | Newbie | | Join Date: Apr 2009
Posts: 2
| | | re: listView messages – how to set listviewItem position - LVM_SETITEMPOSITION?? - public static IntPtr MakeLParam(int wLow, int wHigh)
-
{
-
return (IntPtr)(((short)wHigh << 16) | (wLow & 0xffff));
-
}
-
-
-
[DllImport("coredll.dll", SetLastError = true)]
-
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
-
-
const uint LVM_SETITEMPOSITION = 0x1000 + 15;
-
-
private void function()
-
{
-
-
ImageList imageList = new ImageList();
-
listView.View = System.Windows.Forms.View.LargeIcon;
-
-
-
-
try
-
{
-
-
int x = 0;
-
foreach ()
-
{
-
-
ListViewItem item = new ListViewItem(desc);
-
-
-
//magic
-
int index = listView.Items.Count;
-
-
-
-
IntPtr wparam = (IntPtr)index;
-
IntPtr lparam = MakeLParam(x, 0);
-
-
Message mes = Message.Create(listView.Handle, 0x1000 + 15, wparam, lparam);
-
MessageWindow.SendMessage(ref mes);
-
-
-
-
-
-
-
-
//old
-
//IntPtr listH = listView.Handle;
-
//int index = listView.Items.Count;
-
-
-
//int y = 0;
-
-
//int t = SendMessage(listH, LVM_SETITEMPOSITION, index, m);
-
//IntPtr t = SendMessage(listView.Handle, LVM_SETITEMPOSITION, (IntPtr)index, MakeLParam(x, y));
-
-
x += 20;
-
-
listView.Items.Add(item);
-
-
}
-
-
listView.LargeImageList = imageList;
-
-
}
-
catch (Exception ex)
-
{
-
-
}
-
}
| | Newbie | | Join Date: Apr 2009
Posts: 2
| | | 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);.
|  | Similar Mobile Development bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|