TreeView.FullRowSelect 属性

定义

获取或设置一个值,用以指示选择突出显示是否跨越树视图控件的整个宽度。Gets or sets a value indicating whether the selection highlight spans the width of the tree view control.

public:
 property bool FullRowSelect { bool get(); void set(bool value); };
public bool FullRowSelect { get; set; }
member this.FullRowSelect : bool with get, set
Public Property FullRowSelect As Boolean

属性值

Boolean

如果选择突出显示跨越树视图控件的整个宽度,则为 true;否则为 falsetrue if the selection highlight spans the width of the tree view control; otherwise, false. 默认值为 falseThe default is false.

示例

下面的代码示例演示自定义的 TreeViewThe following code example illustrates a customized TreeView. 通过继承 TreeView 类,此自定义版本具有典型的所有功能 TreeViewBy inheriting the TreeView class, this custom version has all the functionality of a typical TreeView. 更改构造函数中的各种属性值提供了独特的外观。Changing various property values in the constructor provides a unique appearance. 由于 ShowPlusMinus 属性设置为 false ,因此自定义控件也会重写 OnAfterSelect 方法,以便在单击节点时展开和折叠节点。Because the ShowPlusMinus property is set to false, the customized control also overrides the OnAfterSelect method so nodes can be expanded and collapsed when they are clicked.

以这种方式自定义的控件可以在整个组织中使用,从而可以轻松地提供一致的接口,而无需在每个单独的项目中指定控件属性。A control that is customized in this way can be used throughout an organization, making it easy to provide a consistent interface without requiring the control properties to be specified in each individual project.

public ref 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:
   virtual void OnAfterSelect( TreeViewEventArgs^ e ) override
   {
      // 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 = nullptr;
   }
};
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;
    }
}
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


    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

End Class

注解

FullRowSelect 为时 true ,选择突出显示跨越树视图的整个宽度,而不是只显示树节点标签的宽度。When FullRowSelect is true, a selection highlight spans the entire width of the tree view, display instead of the width of just the tree node label. FullRowSelect如果设置为,则忽略属性 ShowLines trueThe FullRowSelect property is ignored if ShowLines is set to true.

适用于