次の方法で共有


TreeViewEventArgs.Action プロパティ

イベントを発生させたアクションの種類を取得します。

Public ReadOnly Property Action As TreeViewAction
[C#]
public TreeViewAction Action {get;}
[C++]
public: __property TreeViewAction get_Action();
[JScript]
public function get Action() : TreeViewAction;

プロパティ値

イベントを発生させた TreeViewAction の種類。

使用例

[Visual Basic, C#, C++] カスタマイズされた TreeView の例を次に示します。 TreeView クラスを継承することにより、このカスタム バージョンには通常の TreeView の機能すべてが備わっています。ここでは、コンストラクタのさまざまなプロパティ値を変更して、固有の外観にします。 ShowPlusMinus プロパティは false に設定されるため、このカスタム コントロールは、ノードがクリックされたときに展開または折りたたみが可能になるように、 OnAfterSelect メソッドもオーバーライドします。

[Visual Basic, C#, C++] このようにしてカスタマイズしたコントロールは階層全体で使用できるため、一貫性のあるインターフェイスが簡単に作成できるようになります。プロジェクトごとにコントロールのさまざまなプロパティを指定する必要はありません。

 
Public Class CustomizedTreeView
    Inherits TreeView

    Public Sub New()
        ' Customize the TreeView control by setting various properties.
        BackColor = System.Drawing.Color.CadetBlue
        FullRowSelect = True
        HotTracking = True
        Indent = 34
        ShowPlusMinus = False

        ' The ShowLines property must be false for the FullRowSelect 
        ' property to work.
        ShowLines = False
    End Sub 'New


    Protected Overrides Sub OnAfterSelect(ByVal e As TreeViewEventArgs)
        ' Confirm that the user initiated the selection.
        ' This prevents the first node from expanding when it is
        ' automatically selected during the initialization of 
        ' the TreeView control.
        If e.Action <> TreeViewAction.Unknown Then
            If e.Node.IsExpanded Then
                e.Node.Collapse()
            Else
                e.Node.Expand()
            End If
        End If

        ' Remove the selection. This allows the same node to be
        ' clicked twice in succession to toggle the expansion state.
        SelectedNode = Nothing
    End Sub 'OnAfterSelect

End Class 'CustomizedTreeView 

[C#] 
public class CustomizedTreeView : TreeView
{
    public CustomizedTreeView()
    {
        // Customize the TreeView control by setting various properties.
        BackColor = System.Drawing.Color.CadetBlue;
        FullRowSelect = true;
        HotTracking = true;
        Indent = 34;
        ShowPlusMinus = false;

        // The ShowLines property must be false for the FullRowSelect 
        // property to work.
        ShowLines = false;
    }

    protected override void OnAfterSelect(TreeViewEventArgs e)
    {
        // Confirm that the user initiated the selection.
        // This prevents the first node from expanding when it is
        // automatically selected during the initialization of 
        // the TreeView control.
        if (e.Action != TreeViewAction.Unknown)
        {
            if (e.Node.IsExpanded) 
            {
                e.Node.Collapse();
            }
            else 
            {
                e.Node.Expand();
            }
        }

        // Remove the selection. This allows the same node to be
        // clicked twice in succession to toggle the expansion state.
        SelectedNode = null;
    }

}

[C++] 
public __gc class CustomizedTreeView : public TreeView
{
public:
    CustomizedTreeView()
    {
        // Customize the TreeView control by setting various properties.
        BackColor = System::Drawing::Color::CadetBlue;
        FullRowSelect = true;
        HotTracking = true;
        Indent = 34;
        ShowPlusMinus = false;

        // The ShowLines property must be false for the FullRowSelect
        // property to work.
        ShowLines = false;
    }

protected:
    void OnAfterSelect(TreeViewEventArgs* e)
    {
        // Confirm that the user initiated the selection.
        // This prevents the first node from expanding when it is
        // automatically selected during the initialization of
        // the TreeView control.
        if (e->Action != TreeViewAction::Unknown)
        {
            if (e->Node->IsExpanded)
            {
                e->Node->Collapse();
            }
            else
            {
                e->Node->Expand();
            }
        }

        // Remove the selection. This allows the same node to be
        // clicked twice in succession to toggle the expansion state.
        SelectedNode = 0;
    }

};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

TreeViewEventArgs クラス | TreeViewEventArgs メンバ | System.Windows.Forms 名前空間 | TreeViewAction