Problem overriding TreeView.OnClick

  • Thread starter Thread starter Mark Erikson
  • Start date Start date
M

Mark Erikson

I'd like to get double-click notification with a TreeView. I've tried
deriving from TreeView and overriding OnClick, as shown in a Microsoft
sample
(http://samples.gotdotnet.com/quickstart/compactframework/doc/btndclick.aspx),
but nothing seems to happen. I've tried setting a breakpoint on the
first line of OnClick, but it doesn't get hit at all. Here's my
current code:

public class TreeViewEx : TreeView
{
private int previousClick = SystemInformation.DoubleClickTime + 1;
public event EventHandler DoubleClick;

protected override void OnClick(EventArgs e)
{
int now = System.Environment.TickCount;
if (now - previousClick <= SystemInformation.DoubleClickTime)
{
MessageBox.Show("Double clicked");
if (DoubleClick != null)
{
DoubleClick(this, EventArgs.Empty);
}
}
previousClick = now;
base.OnClick(e);
}

protected virtual void OnDoubleClick(EventArgs e)
{
if (DoubleClick != null)
{
DoubleClick(this, e);
}
}
}

I get the feeling I'm missing something simple and obvious. Anyone
have any ideas?

Thanks!

Mark Erikson
http://www.isquaredsoftware.com
 
Hi,

On CF, there is no Click event on TreeView, to add it on your own
TreeView, you must hook (override WndProc ...) Windows messages to catch
mouseDown event on TreeView.

I develop an edit TreeView for CF with this solution.
 
Y'know, I just realized my mistake. The MSDN docs say that OnClick is
supported by the Compact Framework, but I only looked at the list of
methods rather than the details of OnClick, where in the fine print
they tell you the list of supported platforms includes ".NET Compact
Framework - Windows CE .NET". In other words, it's in the Compact
Framework, just not in all versions of the Compact Framework (like,
say, the one for PocketPCs).

Nuts. Fortunately, it looks like just using a ContextMenu should
suffice for the purposes of my program. While I'm at it, I had a
question a while back about trying to catch TVN_BEGINDRAG messages
using a WndProc override (done by various methods - ApplicationEx,
native subclassing, etc), and didn't get any answers. If anyone has an
answer to that question
(http://groups.google.com/group/micr...amework.compactframework/msg/51da2634b1ab2855),
I'm still interested in hearing about it.

Thanks!

Mark Erikson
http://www.isquaredsoftware.com
 
Back
Top