Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2007

Tip: Looking for answers? Try searching our database.

SendMessage mouse click to treeview node

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
R.A.F. - 24 Nov 2007 14:47 GMT
Hi,

I would like simulate a mouse click on on of my treeview nodes when my
form opens.

for that i was thinking to use the same simple way as under C++ :
SendMessage(TreeView.Nodes[0].Handle, WM_LBUTTONDOWN,0,0);

but it does not work. i do not get any error message and application
runs normally... just my first node is not selected (clicked).

i want to do that because like that, another childform will be selected
based on my treeview node clicked.

thanks a lot,

RAF
Nicholas Paldino [.NET/C# MVP] - 24 Nov 2007 16:22 GMT
RAF,

   SendMessage is not the way to simulate a mouse click.  It only sends the
message to the control.  A mouse click involves a hardware interrupt,
followed by the OS sending a number of messages to the target window, not
just one button down message.

   In order to send a click to the tree view, you should find the position
of the node you want to send the mouse click to, and then call the SendInput
API function through the P/Invoke layer.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi,
>
[quoted text clipped - 13 lines]
>
> RAF
Kerem Gümrükcü - 24 Nov 2007 16:42 GMT
>In order to send a click to the tree view, you should find the position of
>the node you want to send the mouse click to, and then call the SendInput
>API function through the P/Invoke layer.

Yes, i agree,...would be the best solution for this!

Regards

Kerem

Signature

-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Microsoft Live Space: http://kerem-g.spaces.live.com/
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."

R.A.F. - 24 Nov 2007 19:07 GMT
Sorry Nicholas but i did not find anything in VS2008 help about
SendInput API.

By the way, why do you not support the SendMessage method for such topic ?

I finally adapt it from C++ to C# and it works great :-)

RAF

> RAF,
>
[quoted text clipped - 6 lines]
> position of the node you want to send the mouse click to, and then call
> the SendInput API function through the P/Invoke layer.
Nicholas Paldino [.NET/C# MVP] - 24 Nov 2007 19:34 GMT
RAF,

   Here is a link to the documentation for SendInput:

http://msdn2.microsoft.com/en-us/library/ms646310.aspx

   The reason I don't like calling SendMessage in this case is that you are
only sending the left mouse button down message.  However, a true mouse
click consists of a click event, as well as a mouse down and a mouse up
event and possibly more.  The control is also free to respond to any of
these messages as it sees fit.

   It just so happens that sending the message is doing what you want, but
it isn't the same as sending a mouse click.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Sorry Nicholas but i did not find anything in VS2008 help about SendInput
> API.
[quoted text clipped - 15 lines]
>> position of the node you want to send the mouse click to, and then call
>> the SendInput API function through the P/Invoke layer.
KWienhold - 26 Nov 2007 11:53 GMT
> Hi,
>
[quoted text clipped - 13 lines]
>
> RAF

Maybe I'm missing something here, but if you want to make sure that
that a specific node is selected when your form opens, why not simply
set the SelectedNode property of the tree?
Since the most common way to use a tree for navigation is to handle
the AfterSelect event, this should result in the same behavior as
actually clicking on the node.

hth,
Kevin Wienhold

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.