.NET

Reply
*Scott McFarlane
Message 1 of 12 (254 Views)

TreeView label edit in a palette

254 Views, 11 Replies
08-25-2005 11:01 AM
My .NET application creates a new PaletteSet using a user control that has a
TreeView on it. The TreeView allows label editing, but once you are in label
editing mode, the control does not respond to either ESC or ENTER. I seem to
recall having to deal with this issue in a similar ObjectARX application,
but I'm not sure how to fix it in .NET.

Below is a snippet of code that demonstrates this issue:

With New Autodesk.AutoCAD.Windows.PaletteSet("Test Palette")
Dim objTreeView As New System.Windows.Forms.TreeView
With objTreeView
.Dock = Windows.Forms.DockStyle.Fill
.LabelEdit = True
.Nodes.Add("Edit this node")
End With
.Add("Test Palette", objTreeView)
.Visible = True
End With

Any ideas?

Scott
*Mike Tuersley
Message 2 of 12 (254 Views)

Re: TreeView label edit in a palette

08-25-2005 08:35 PM in reply to: *Scott McFarlane
I assume you have coded the node's KeyUp event to handle Enter and/or
Escape?

-- Mike
___________________________
Mike Tuersley
___________________________
the trick is to realize that there is no spoon...
*Mike Tuersley
Message 3 of 12 (254 Views)

Re: TreeView label edit in a palette

08-26-2005 06:30 AM in reply to: *Scott McFarlane
Oops, let me rephrase that.! What I meant to say was have you tried
throwing code into the keyup event for the treeview and the palette to see
if the event registering at all one either of those keys? If not, you may
need the same fix for focus as the combobox control.

-- Mike
___________________________
Mike Tuersley
___________________________
the trick is to realize that there is no spoon...
*Scott McFarlane
Message 4 of 12 (254 Views)

Re: TreeView label edit in a palette

08-26-2005 10:23 AM in reply to: *Scott McFarlane
Hi Mike,

Thanks for the reply. The PaletteSet and Palette classes don't appear to
expose any keyboard events themselves. I tried putting some code into the
TreeView's KeyUp event and found that it responds to ESC and ENTER. But when
you go into label edit mode (and the TreeView control creates a temporary
edit box control to edit the label) those keys seem to be ignored - in fact,
the TreeView_KeyUp event is not fired at all when the label edit box is
visible.

- Scott


"Mike Tuersley" wrote in message
news:4939864@discussion.autodesk.com...
Oops, let me rephrase that.! What I meant to say was have you tried
throwing code into the keyup event for the treeview and the palette to see
if the event registering at all one either of those keys? If not, you may
need the same fix for focus as the combobox control.

-- Mike
___________________________
Mike Tuersley
___________________________
the trick is to realize that there is no spoon...
*Tony Tanzillo
Message 5 of 12 (254 Views)

Re: TreeView label edit in a palette

08-26-2005 12:36 PM in reply to: *Scott McFarlane
"Mike Tuersley" wrote:

> If not, you may need the same fix for focus
> as the combobox control.

Hi Mike. You might be interested in knowing that
the 'fix' you posted for the ComboBox problem (for
not dropping down when you click on the control
while the palette is floating), actually creates more
problems than it solves.

One of those problems is that it corrupts the behavior
of any control that displays an "in-place" edit window
(e.g, TreeView, ListView, DataGrid, etc.).

With your fix, if you try editing a label in a treeview
or listview, and you click inside the label edit window
with the mouse, the label edit window looses and
regains focus, with the entire label text selected.
What should happen is that you should get a vertical
blinking bar cursor at the point where you clicked in
the control, but that doesn't happen.

I haven't looked at the problem with the treeview
(and it should also affect ListViews as well), so I
don't know exactly what's causing it.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com
*Mike Tuersley
Message 6 of 12 (254 Views)

Re: TreeView label edit in a palette

08-26-2005 09:47 PM in reply to: *Scott McFarlane
Ouch! Sorry, I didn't mean for that to happen =( Chalk another one up to
"slap it in and see if it works to get me to the due date and I'll sort it
out later"

I'll look at it and weed out the crap and see if I can't revise it with
just the focus you mentioned, Tony. Thanks!

-- Mike
___________________________
Mike Tuersley
___________________________
the trick is to realize that there is no spoon...
*Tony Tanzillo
Message 7 of 12 (254 Views)

Re: TreeView label edit in a palette

08-27-2005 10:45 PM in reply to: *Scott McFarlane
This TreeView control descendent should solve your problem.
Just use it in lieu of the Syste.Windows.Forms.TreeView.

Sorry about the C#, but I don't do VB. Hopefully, somoene can
translate it for you, or you can build it a separate assembly and
reference it from your VB project.

//////////////////////////////////////////////////////////////////////////////////////
/// DialogTreeView.cs Cooyright (c) 2005 Tony Tanzillo All rights reserved
///
/// For private use only. Do not distribute or
/// publish this code without the express written
/// consent of the author.
///
/// This TreeView descendent addresses the issue
/// described in KB 130691
///
/// See http://support.microsoft.com/default.aspx?scid=kb;en-us;130691

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace StupidControlThunks
{
public class DialogTreeView : TreeView
{
public DialogTreeView()
{
}

private const int TVM_GETEDITCONTROL = 0x110F;

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd,
int msg, int wParam, int lParam);

private class LabelEditWindowHook : NativeWindow
{
private const int WM_GETDLGCODE = 135;
private const int DLGC_WANTALLKEYS = 0x0004;

public LabelEditWindowHook()
{
}
protected override void WndProc(ref Message m)
{
if( m.Msg == WM_GETDLGCODE )
m.Result = (IntPtr) DLGC_WANTALLKEYS;
else
base.WndProc(ref m);
}
}

private LabelEditWindowHook m_Hook = new LabelEditWindowHook();

protected override void OnBeforeLabelEdit( NodeLabelEditEventArgs e )
{
IntPtr handle = SendMessage(this.Handle, TVM_GETEDITCONTROL, 0, 0);
if( handle != IntPtr.Zero )
m_Hook.AssignHandle(handle);
base.OnBeforeLabelEdit( e );
}

protected override void OnAfterLabelEdit( NodeLabelEditEventArgs e )
{
m_Hook.ReleaseHandle();
base.OnAfterLabelEdit( e );
}
}
}

/////// DialogTreeView.cs ///////////////////////////////////////////////////

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Scott McFarlane" wrote in message news:4939035@discussion.autodesk.com...
My .NET application creates a new PaletteSet using a user control that has a
TreeView on it. The TreeView allows label editing, but once you are in label
editing mode, the control does not respond to either ESC or ENTER. I seem to
recall having to deal with this issue in a similar ObjectARX application,
but I'm not sure how to fix it in .NET.

Below is a snippet of code that demonstrates this issue:

With New Autodesk.AutoCAD.Windows.PaletteSet("Test Palette")
Dim objTreeView As New System.Windows.Forms.TreeView
With objTreeView
.Dock = Windows.Forms.DockStyle.Fill
.LabelEdit = True
.Nodes.Add("Edit this node")
End With
.Add("Test Palette", objTreeView)
.Visible = True
End With

Any ideas?

Scott
*Tony Tanzillo
Message 8 of 12 (254 Views)

Re: TreeView label edit in a palette

08-28-2005 10:00 PM in reply to: *Scott McFarlane
Fixed version:

//////////////////////////////////////////////////////////////////////////////////////
/// DialogTreeView.cs Cooyright (c) 2005 Tony Tanzillo All rights reserved
///
/// For private use only. Do not distribute or
/// publish this code without the express written
/// consent of the author.
///
/// This TreeView descendent addresses the issue
/// described in KB 130691
///
/// See http://support.microsoft.com/default.aspx?scid=kb;en-us;130691

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace StupidControlThunks
{
public class DialogTreeView : TreeView
{
public DialogTreeView()
{
}

private const int TVM_GETEDITCONTROL = 0x110F;

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd,
int msg, int wParam, int lParam);

private class LabelEditWindowHook : NativeWindow
{
private const int WM_GETDLGCODE = 135;
private const int DLGC_WANTALLKEYS = 0x0004;

public LabelEditWindowHook()
{
}
protected override void WndProc(ref Message m)
{
if( m.Msg == WM_GETDLGCODE )
m.Result = (IntPtr) DLGC_WANTALLKEYS;
else
base.WndProc(ref m);
}
}

private LabelEditWindowHook m_Hook = new LabelEditWindowHook();

protected override void OnBeforeLabelEdit( NodeLabelEditEventArgs e )
{
base.OnBeforeLabelEdit( e );
if( ! e.CancelEdit )
{
IntPtr handle = SendMessage(this.Handle, TVM_GETEDITCONTROL, 0, 0);
if( handle != IntPtr.Zero )
m_Hook.AssignHandle(handle);
}
}
}
}

/////// DialogTreeView.cs ///////////////////////////////////////////////////



--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Tony Tanzillo" wrote in message news:4941045@discussion.autodesk.com...
This TreeView control descendent should solve your problem.
Just use it in lieu of the Syste.Windows.Forms.TreeView.

Sorry about the C#, but I don't do VB. Hopefully, somoene can
translate it for you, or you can build it a separate assembly and
reference it from your VB project.

//////////////////////////////////////////////////////////////////////////////////////
/// DialogTreeView.cs Cooyright (c) 2005 Tony Tanzillo All rights reserved
///
/// For private use only. Do not distribute or
/// publish this code without the express written
/// consent of the author.
///
/// This TreeView descendent addresses the issue
/// described in KB 130691
///
/// See http://support.microsoft.com/default.aspx?scid=kb;en-us;130691

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace StupidControlThunks
{
public class DialogTreeView : TreeView
{
public DialogTreeView()
{
}

private const int TVM_GETEDITCONTROL = 0x110F;

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd,
int msg, int wParam, int lParam);

private class LabelEditWindowHook : NativeWindow
{
private const int WM_GETDLGCODE = 135;
private const int DLGC_WANTALLKEYS = 0x0004;

public LabelEditWindowHook()
{
}
protected override void WndProc(ref Message m)
{
if( m.Msg == WM_GETDLGCODE )
m.Result = (IntPtr) DLGC_WANTALLKEYS;
else
base.WndProc(ref m);
}
}

private LabelEditWindowHook m_Hook = new LabelEditWindowHook();

protected override void OnBeforeLabelEdit( NodeLabelEditEventArgs e )
{
IntPtr handle = SendMessage(this.Handle, TVM_GETEDITCONTROL, 0, 0);
if( handle != IntPtr.Zero )
m_Hook.AssignHandle(handle);
base.OnBeforeLabelEdit( e );
}

protected override void OnAfterLabelEdit( NodeLabelEditEventArgs e )
{
m_Hook.ReleaseHandle();
base.OnAfterLabelEdit( e );
}
}
}

/////// DialogTreeView.cs ///////////////////////////////////////////////////

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Scott McFarlane" wrote in message news:4939035@discussion.autodesk.com...
My .NET application creates a new PaletteSet using a user control that has a
TreeView on it. The TreeView allows label editing, but once you are in label
editing mode, the control does not respond to either ESC or ENTER. I seem to
recall having to deal with this issue in a similar ObjectARX application,
but I'm not sure how to fix it in .NET.

Below is a snippet of code that demonstrates this issue:

With New Autodesk.AutoCAD.Windows.PaletteSet("Test Palette")
Dim objTreeView As New System.Windows.Forms.TreeView
With objTreeView
.Dock = Windows.Forms.DockStyle.Fill
.LabelEdit = True
.Nodes.Add("Edit this node")
End With
.Add("Test Palette", objTreeView)
.Visible = True
End With

Any ideas?

Scott
*Tony Tanzillo
Message 9 of 12 (254 Views)

Re: TreeView label edit in a palette

08-29-2005 10:01 AM in reply to: *Scott McFarlane
The code below has a major bug. Don't use it.

See the next post for a fixed version.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Tony Tanzillo" wrote in message news:4941045@discussion.autodesk.com...
This TreeView control descendent should solve your problem.
Just use it in lieu of the Syste.Windows.Forms.TreeView.

Sorry about the C#, but I don't do VB. Hopefully, somoene can
translate it for you, or you can build it a separate assembly and
reference it from your VB project.

//////////////////////////////////////////////////////////////////////////////////////
/// DialogTreeView.cs Cooyright (c) 2005 Tony Tanzillo All rights reserved
///
/// For private use only. Do not distribute or
/// publish this code without the express written
/// consent of the author.
///
/// This TreeView descendent addresses the issue
/// described in KB 130691
///
/// See http://support.microsoft.com/default.aspx?scid=kb;en-us;130691

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace StupidControlThunks
{
public class DialogTreeView : TreeView
{
public DialogTreeView()
{
}

private const int TVM_GETEDITCONTROL = 0x110F;

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd,
int msg, int wParam, int lParam);

private class LabelEditWindowHook : NativeWindow
{
private const int WM_GETDLGCODE = 135;
private const int DLGC_WANTALLKEYS = 0x0004;

public LabelEditWindowHook()
{
}
protected override void WndProc(ref Message m)
{
if( m.Msg == WM_GETDLGCODE )
m.Result = (IntPtr) DLGC_WANTALLKEYS;
else
base.WndProc(ref m);
}
}

private LabelEditWindowHook m_Hook = new LabelEditWindowHook();

protected override void OnBeforeLabelEdit( NodeLabelEditEventArgs e )
{
IntPtr handle = SendMessage(this.Handle, TVM_GETEDITCONTROL, 0, 0);
if( handle != IntPtr.Zero )
m_Hook.AssignHandle(handle);
base.OnBeforeLabelEdit( e );
}

protected override void OnAfterLabelEdit( NodeLabelEditEventArgs e )
{
m_Hook.ReleaseHandle();
base.OnAfterLabelEdit( e );
}
}
}

/////// DialogTreeView.cs ///////////////////////////////////////////////////

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Scott McFarlane" wrote in message news:4939035@discussion.autodesk.com...
My .NET application creates a new PaletteSet using a user control that has a
TreeView on it. The TreeView allows label editing, but once you are in label
editing mode, the control does not respond to either ESC or ENTER. I seem to
recall having to deal with this issue in a similar ObjectARX application,
but I'm not sure how to fix it in .NET.

Below is a snippet of code that demonstrates this issue:

With New Autodesk.AutoCAD.Windows.PaletteSet("Test Palette")
Dim objTreeView As New System.Windows.Forms.TreeView
With objTreeView
.Dock = Windows.Forms.DockStyle.Fill
.LabelEdit = True
.Nodes.Add("Edit this node")
End With
.Add("Test Palette", objTreeView)
.Visible = True
End With

Any ideas?

Scott
*Scott McFarlane
Message 10 of 12 (254 Views)

Re: TreeView label edit in a palette

08-29-2005 12:38 PM in reply to: *Scott McFarlane
Hi Tony,

Works like a charm. Thanks!

Scott


"Tony Tanzillo" wrote in message
news:4941243@discussion.autodesk.com...
Fixed version:

//////////////////////////////////////////////////////////////////////////////////////
/// DialogTreeView.cs Cooyright (c) 2005 Tony Tanzillo All rights
reserved
///
/// For private use only. Do not distribute or
/// publish this code without the express written
/// consent of the author.
///
/// This TreeView descendent addresses the issue
/// described in KB 130691
///
/// See http://support.microsoft.com/default.aspx?scid=kb;en-us;130691

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace StupidControlThunks
{
public class DialogTreeView : TreeView
{
public DialogTreeView()
{
}

private const int TVM_GETEDITCONTROL = 0x110F;

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd,
int msg, int wParam, int lParam);

private class LabelEditWindowHook : NativeWindow
{
private const int WM_GETDLGCODE = 135;
private const int DLGC_WANTALLKEYS = 0x0004;

public LabelEditWindowHook()
{
}
protected override void WndProc(ref Message m)
{
if( m.Msg == WM_GETDLGCODE )
m.Result = (IntPtr) DLGC_WANTALLKEYS;
else
base.WndProc(ref m);
}
}

private LabelEditWindowHook m_Hook = new LabelEditWindowHook();

protected override void OnBeforeLabelEdit( NodeLabelEditEventArgs e )
{
base.OnBeforeLabelEdit( e );
if( ! e.CancelEdit )
{
IntPtr handle = SendMessage(this.Handle, TVM_GETEDITCONTROL, 0,
0);
if( handle != IntPtr.Zero )
m_Hook.AssignHandle(handle);
}
}
}
}

/////// DialogTreeView.cs
///////////////////////////////////////////////////



--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Tony Tanzillo" wrote in message
news:4941045@discussion.autodesk.com...
This TreeView control descendent should solve your problem.
Just use it in lieu of the Syste.Windows.Forms.TreeView.

Sorry about the C#, but I don't do VB. Hopefully, somoene can
translate it for you, or you can build it a separate assembly and
reference it from your VB project.

//////////////////////////////////////////////////////////////////////////////////////
/// DialogTreeView.cs Cooyright (c) 2005 Tony Tanzillo All rights
reserved
///
/// For private use only. Do not distribute or
/// publish this code without the express written
/// consent of the author.
///
/// This TreeView descendent addresses the issue
/// described in KB 130691
///
/// See http://support.microsoft.com/default.aspx?scid=kb;en-us;130691

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace StupidControlThunks
{
public class DialogTreeView : TreeView
{
public DialogTreeView()
{
}

private const int TVM_GETEDITCONTROL = 0x110F;

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd,
int msg, int wParam, int lParam);

private class LabelEditWindowHook : NativeWindow
{
private const int WM_GETDLGCODE = 135;
private const int DLGC_WANTALLKEYS = 0x0004;

public LabelEditWindowHook()
{
}
protected override void WndProc(ref Message m)
{
if( m.Msg == WM_GETDLGCODE )
m.Result = (IntPtr) DLGC_WANTALLKEYS;
else
base.WndProc(ref m);
}
}

private LabelEditWindowHook m_Hook = new LabelEditWindowHook();

protected override void OnBeforeLabelEdit( NodeLabelEditEventArgs e )
{
IntPtr handle = SendMessage(this.Handle, TVM_GETEDITCONTROL, 0, 0);
if( handle != IntPtr.Zero )
m_Hook.AssignHandle(handle);
base.OnBeforeLabelEdit( e );
}

protected override void OnAfterLabelEdit( NodeLabelEditEventArgs e )
{
m_Hook.ReleaseHandle();
base.OnAfterLabelEdit( e );
}
}
}

/////// DialogTreeView.cs
///////////////////////////////////////////////////

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Scott McFarlane" wrote in message
news:4939035@discussion.autodesk.com...
My .NET application creates a new PaletteSet using a user control that has a
TreeView on it. The TreeView allows label editing, but once you are in label
editing mode, the control does not respond to either ESC or ENTER. I seem to
recall having to deal with this issue in a similar ObjectARX application,
but I'm not sure how to fix it in .NET.

Below is a snippet of code that demonstrates this issue:

With New Autodesk.AutoCAD.Windows.PaletteSet("Test Palette")
Dim objTreeView As New System.Windows.Forms.TreeView
With objTreeView
.Dock = Windows.Forms.DockStyle.Fill
.LabelEdit = True
.Nodes.Add("Edit this node")
End With
.Add("Test Palette", objTreeView)
.Visible = True
End With

Any ideas?

Scott
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.