473,404 Members | 2,170 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,404 software developers and data experts.

Getting ListView items in C# from SysListView32 using SendMessage

Hi

I am trying to access the listview items from a SysListView32 control
in C#. I am using LVM.FINDITEM and LVFINDINFO through SendMessage to
try to get the text from each column in the item (it is a multi-column
list view).

I am using the PARTIAL flag to try to find an item starting with a
certain letter, that i am setting on the LVFINDINFO.psz. I am always
being returned -1 (or 0) as the index and am not quite sure what i am
doing wrong - i hate Win32! Could someone be able to outline the steps
i need to take, given the handle to the syslistview32 control, to get
an item from a multi-column listview and find out the text in each
column for that item?

Many thanks

Dave
Nov 16 '05 #1
3 17008
Dave,

Is the listview in your application or in a different process? Most of
these messages will only work in the same process since the message
parameters don't marshal correctly cross process boundaries.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
Hi
Thanks for your reply. The listview is in another process. I can use
SendMessage to get information from a RichTextBox and a ComboBox. I was
very much hoping i could do the same with the listview. To be honest, i
am fairly new to Win32 so it is probably the basics i have got wrong.

Would it be possible to list the steps i would need to take to make this
work. Currently, my calling code is:

internal unsafe int ListView_FindItem(IntPtr lv, int iStart,
ref LVFINDINFO lvfi)
{
LVFINDINFO_INTERNAL lvfii = new LVFINDINFO_INTERNAL();

lvfii.flags = lvfi.flags;
lvfii.lParam = lvfi.lParam;
lvfii.vkDirection = lvfi.vkDirection;
lvfii.pt = new POINT();
lvfii.pt.x = lvfi.pt.X;
lvfii.pt.y = lvfi.pt.Y;
if(lvfi.psz != null)
{
fixed(char* ptr = lvfi.psz.ToCharArray())
{
lvfii.psz = ptr;
return SendMessage(lv, (int)LVM.FINDITEM, (uint)iStart,
new IntPtr(&lvfii).ToInt32());
}
}
return SendMessage(lv, (int)LVM.FINDITEM, (uint)iStart,
new IntPtr(&lvfii).ToInt32());
}

public string FindInfo( IntPtr listView, string find )
{
LVFINDINFO lvfi = new LVFINDINFO();
lvfi.flags = LVFI.PARTIAL;
lvfi.psz = "A";
int returned = ListView_FindItem(listView, -1, ref lvfi);
return lvfi.psz;
}

It compiles and runs without error (apart from the lack of output), so
am assuming all my definitions are ok.

Am i correct in assuming lvfi.psz should contain the text an the return
value of SendMessage contain the index!?

Many thanks for your help

Dave

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
David,
I can use
SendMessage to get information from a RichTextBox and a ComboBox.
Because Windows knows how to marshal those messages.

Would it be possible to list the steps i would need to take to make this
work.


It's far from trivial, and probably not something you want to do in
managed code. One way is to inject code to run in the foreign process
(CreateRemoteThread for example), and make that pass the data back via
some shared memory.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Lauwers | last post by:
I know you can edit the first column of the listview control, is there a way to edit the second and/or the other columns? greets John
6
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
0
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
2
by: Anushya devi | last post by:
Hi All I used listview and tried to update it by using Addrange. When the number of items is less, it works fine.. But I need to update nearly 200,000 items and it hangs. Also i need to add...
12
by: Mike Smith | last post by:
Hey anyone knows how to find an item in a list view based on text ? Cant seem to get the IndexOf method working. would the LVM_FINDITEM method using SendMessage API work in .Net ?
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...
10
by: Adam Honek | last post by:
This is probably a silly question but oh well, I can't find the answer looking via code. Having an imagelist already, how does one set an icon for a list view's sub items? I'm using the code...
3
by: geskerrett | last post by:
Hope someone can steer me in the right direction. I am trying to use python to collect the values from a Win32 application's control. I can successfull query an retreive the values ListBox, Edit...
2
by: witpo | last post by:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.