TreeView Missing SelectedItemChanged Event?

J

Jeffrey Walton

Hi All,

Sorry about this beginner question (I'm coming up from Visual C++ or
Down from VB)... Also, pickings are slim for this topic on MSDN [1,
2]. [2] does not really apply, but it was a keyword hit
("SelectedItemChanged"). Does any one know how to receive this
notification? I'm not receiving it.

What I done so far: Hightlight the TreeView in Design Mode, and then
switching to Properties->Events: SelectedItemChanged is not an
available event. I tried the following (TreeView control name is
ObjectTree):

private void ObjectTree_SelectedItemChanged(object sender, EventArgs
e)
{...}

I have no idea what to do with (from [1]):

public static readonly RoutedEvent SelectedItemChangedEvent

Pasting it into the code resulted in compile errors. The Microsoft
Wiki [3] is looking more appealing every day. Sorry about another
beginner question.

Jeff

[1] TreeView.SelectedItemChangedEvent Field,
http://msdn2.microsoft.com/en-us/li...ntrols.treeview.selecteditemchangedevent.aspx
[2] DomainUpDown.SelectedItemChanged Event,
http://msdn2.microsoft.com/en-us/library/system.windows.forms.domainupdown.selecteditemchanged.aspx
[3] Microsoft Wiki, http://msdn2.microsoft.com/en-us/library/bb166441(VS.80).aspx
 
P

Peter Duniho

[...]
What I done so far: Hightlight the TreeView in Design Mode, and then
switching to Properties->Events: SelectedItemChanged is not an
available event.

That's right, it's not. There is no such event in the original
TreeView control.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.treeview_events.aspx

I
tried the following (TreeView control name is
ObjectTree):

private void ObjectTree_SelectedItemChanged(object sender, EventArgs
e)
{...}

I have no idea what to do with (from [1]):

If there were such an event, then you could subscribe that method to
the event. But there's not, so you can't.

The TreeView control does have other events that _might_ be useful,
such as BeforeSelect or AfterSelect. Kind of depends on what you're
trying to do though.
public static readonly RoutedEvent SelectedItemChangedEvent

Pasting it into the code resulted in compile errors.

Looks like you're looking at the wrong section of the documentation. A
Windows forms application will be using the TreeView class from the
System.Windows.Forms namespace, not the System.Windows.Controls
namespace.

If you are in fact trying to use the TreeView class from the Controls
namespace, then you need to make sure you have the appropriate
reference and using statement for that. That class is, however, for
when you're using WPF.

Pete
 
J

Jeffrey Walton

Hi Pete,

Thanks. I found I had to use AfterSelectionChange (or whatever C#
calls it - I don't have the code in front of me).

Jeff

[...]
What I done so far: Hightlight the TreeView in Design Mode, and then
switching to Properties->Events: SelectedItemChanged is not an
available event.

That's right, it's not. There is no such event in the original
TreeView control.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.treevie...

I
tried the following (TreeView control name is
ObjectTree):
private void ObjectTree_SelectedItemChanged(object sender, EventArgs
e)
{...}
I have no idea what to do with (from [1]):

If there were such an event, then you could subscribe that method to
the event. But there's not, so you can't.

The TreeView control does have other events that _might_ be useful,
such as BeforeSelect or AfterSelect. Kind of depends on what you're
trying to do though.
public static readonly RoutedEvent SelectedItemChangedEvent
Pasting it into the code resulted in compile errors.

Looks like you're looking at the wrong section of the documentation. A
Windows forms application will be using the TreeView class from the
System.Windows.Forms namespace, not the System.Windows.Controls
namespace.

If you are in fact trying to use the TreeView class from the Controls
namespace, then you need to make sure you have the appropriate
reference and using statement for that. That class is, however, for
when you're using WPF.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top