By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,313 Members | 2,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,313 IT Pros & Developers. It's quick & easy.

Double Click in treeView

P: n/a
Is there a way to avoid the default action of TreeNode expansion/contraction
caused by double click? I can add an event handler to pop up my properties
dialog on double click, but it has the unintended side-effect of toggling
the expansion of that subtree.

Thanks in advance,
Brian
Nov 15 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

Hi Brian,

I think you can subclass this control and do any operation before the
default procedure.
For example, in the WM_LBUTTONDBLCLK message, you can block the the
processing and return.

HTH.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Brian Smith" <br****@cmicro.com>
| Subject: Double Click in treeView
| Date: Mon, 18 Aug 2003 17:40:02 -0700
| Lines: 9
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uZ**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: watchguard.cmicro.com 198.107.63.34
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:177274
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Is there a way to avoid the default action of TreeNode
expansion/contraction
| caused by double click? I can add an event handler to pop up my
properties
| dialog on double click, but it has the unintended side-effect of toggling
| the expansion of that subtree.
|
| Thanks in advance,
| Brian
|
|
|

Nov 15 '05 #2

P: n/a
So, you're saying that there is no way to do this without subclassing the
control? I was hoping to avoid that.

"Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
news:qh**************@cpmsftngxa06.phx.gbl...

Hi Brian,

I think you can subclass this control and do any operation before the
default procedure.
For example, in the WM_LBUTTONDBLCLK message, you can block the the
processing and return.

HTH.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Nov 15 '05 #3

P: n/a

Hi Brian,

You also can override the treeview control's wndproc method and process the
WM_LBUTTONDBLCLK
message.
The actual value of the const WM_LBUTTONDBLCLK can be retrieved in "API
text viewer" followed by
Visual Studio 6.0

For example:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace treeview
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
public const int WM_LBUTTONDBLCLK = 0x203;
private newtreeview treeView1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
class newtreeview: TreeView
{
protected override void WndProc(ref Message m)
{
switch(m.Msg )
{
case WM_LBUTTONDBLCLK:
MessageBox.Show ("db click");
return;
break;
}
base.WndProc (ref m);
}
}

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.treeView1 = new newtreeview();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.ImageIndex = -1;
this.treeView1.Location = new System.Drawing.Point(40, 32);
this.treeView1.Name = "treeView1";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node0", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node4", new System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node5")})}),
new System.Windows.Forms.TreeNode("Node1", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node6", new System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node8")}),
new
System.Windows.Forms.TreeNode("Node7")}),
new System.Windows.Forms.TreeNode("Node2"),
new System.Windows.Forms.TreeNode("Node3")});
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(208, 208);
this.treeView1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}

HTH.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Brian Smith" <br****@cmicro.com>
| References: <uZ**************@tk2msftngp13.phx.gbl>
<qh**************@cpmsftngxa06.phx.gbl>
| Subject: Re: Double Click in treeView
| Date: Tue, 19 Aug 2003 09:26:27 -0700
| Lines: 22
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <Op**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: watchguard.cmicro.com 198.107.63.34
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:177488
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| So, you're saying that there is no way to do this without subclassing the
| control? I was hoping to avoid that.
|
| "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| news:qh**************@cpmsftngxa06.phx.gbl...
| >
| > Hi Brian,
| >
| > I think you can subclass this control and do any operation before the
| > default procedure.
| > For example, in the WM_LBUTTONDBLCLK message, you can block the the
| > processing and return.
| >
| > HTH.
| >
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
|
|
|
|

Nov 15 '05 #4

P: n/a
Thank you. I have already done this and it works well. It is, however, odd
that this double-click behavior is not optional.
You also can override the treeview control's wndproc method and process the WM_LBUTTONDBLCLK message.
The actual value of the const WM_LBUTTONDBLCLK can be retrieved in "API
text viewer" followed by Visual Studio 6.0

Nov 15 '05 #5

P: n/a

Hi Brian,

What does your "optional" mean?
Do you mean that the double click message is not an optional event that can
be handle?

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Brian Smith" <br****@cmicro.com>
| References: <uZ**************@tk2msftngp13.phx.gbl>
<qh**************@cpmsftngxa06.phx.gbl>
<Op**************@TK2MSFTNGP12.phx.gbl>
<34**************@cpmsftngxa06.phx.gbl>
| Subject: Re: Double Click in treeView
| Date: Wed, 20 Aug 2003 11:04:08 -0700
| Lines: 10
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#s**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: watchguard.cmicro.com 198.107.63.34
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:177851
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thank you. I have already done this and it works well. It is, however,
odd
| that this double-click behavior is not optional.
|
| > You also can override the treeview control's wndproc method and process
| the
| > WM_LBUTTONDBLCLK message.
| > The actual value of the const WM_LBUTTONDBLCLK can be retrieved in "API
| > text viewer" followed by Visual Studio 6.0
|
|
|

Nov 15 '05 #6

P: n/a

Hi Brian,

Thank you for your post.
I understand your meaning.
You believe that the treeview control should not be expend behavior when
double click by default.
But I think in most treeview control in windows software, its double click
behavior is expend and this
behavior fits for the user's convention.
The different behavior in outlook and VS.net is special, so the treeview
control provides wndproc can
be overrride to change the default behavior.

May be, we are just different on opinion, you can give this suggestion to
microsoft at:
http://register.microsoft.com/mswish/suggestion.asp
Thank you for your suggestion.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Brian Smith" <br****@cmicro.com>
| References: <uZ**************@tk2msftngp13.phx.gbl>
<qh**************@cpmsftngxa06.phx.gbl>
<Op**************@TK2MSFTNGP12.phx.gbl>
<34**************@cpmsftngxa06.phx.gbl>
<#s**************@TK2MSFTNGP10.phx.gbl>
<ZN**************@cpmsftngxa06.phx.gbl>
| Subject: Re: Double Click in treeView
| Date: Thu, 21 Aug 2003 15:33:38 -0700
| Lines: 15
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uI**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: watchguard.cmicro.com 198.107.63.34
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:178378
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| > What does your "optional" mean?
| > Do you mean that the double click message is not an optional event that
| can
| > be handle?
|
| I mean the action of toggling the expanded state of the currently selected
| node is not optional. Whenever a double click event happens, the node
under
| the mouse cursor is expanded or collapsed. This is not what I expect
from a
| TreeView. Does Outlook Express do that for the treeview of news posts?
No.
| Does Visual Studio do that for the treeviews for the explorers (solution,
| class, resource, etc...) on the right-hand side? No. Simply, it is
| non-standard behavior when integrating the TreeView control into a UI.
So,
| I am surprised that Microsoft made it difficult to overide this behavior.
|
|
|

Nov 15 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.