Udostępnij za pośrednictwem


ListObject.AutoSelectRows Property (2007 System)

Gets or sets a value that indicates whether the entire row is selected when the SelectedIndex changes.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
Public Property AutoSelectRows As Boolean
'Usage
Dim instance As ListObject 
Dim value As Boolean 

value = instance.AutoSelectRows

instance.AutoSelectRows = value
public bool AutoSelectRows { get; set; }
public:
property bool AutoSelectRows {
    bool get ();
    void set (bool value);
}
public function get AutoSelectRows () : boolean 
public function set AutoSelectRows (value : boolean)

Property Value

Type: System.Boolean
true to select the entire row; otherwise, false. The default is false.

Remarks

The entire row in the ListObject control user interface that corresponds to the SelectedIndex is selected when this property is set to true.

Examples

The following code example creates a ListObject on the current worksheet. It uses the SelectedIndex and AutoSelectRows properties to select the second row and to specify that the entire row is selected when the user clicks a row. The code example also creates an event handler for the SelectedIndexChanged event that displays a message box whenever a new row is selected.

This version is for a document-level customization.

WithEvents SelectedIndexList As Microsoft.Office.Tools.Excel.ListObject
    Private Sub ListObject_SelectedIndex()
        SelectedIndexList = _
            Me.Controls.AddListObject(Me.Range("A1", "D4"), _
            "SelectedIndexList")
    SelectedIndexList.AutoSelectRows = True
        SelectedIndexList.SelectedIndex = 2
    End Sub 


    Private Sub List1_SelectedIndexChanged(ByVal sender As Object, _
        ByVal e As EventArgs) Handles SelectedIndexList.SelectedIndexChanged
        MessageBox.Show("Selected index has changed.")
    End Sub
private void ListObject_SelectedIndex()
{
    Microsoft.Office.Tools.Excel.ListObject list1 =
        this.Controls.AddListObject(this.Range["A1", "D4"],
        "list1");

    list1.AutoSelectRows = true;
    list1.SelectedIndex = 2;
    list1.SelectedIndexChanged +=
        new EventHandler(list1_SelectedIndexChanged);
}

void list1_SelectedIndexChanged(object sender, EventArgs e)
{
    MessageBox.Show("Selected index has changed.");
}

This version is for an application-level add-in.

WithEvents SelectedIndexList As ListObject
Private Sub ListObject_SelectedIndex()
    Dim vstoWorksheet As Worksheet = CType( _
        Me.Application.ActiveWorkbook.Worksheets(1),  _
        Excel.Worksheet).GetVstoObject()
    SelectedIndexList = _
        vstoWorksheet.Controls.AddListObject( _
        vstoWorksheet.Range("A1", "D4"), _
        "SelectedIndexList")
    SelectedIndexList.AutoSelectRows = True
    SelectedIndexList.SelectedIndex = 2
End Sub 


Private Sub List1_SelectedIndexChanged(ByVal sender As Object, _
    ByVal e As EventArgs) Handles SelectedIndexList.SelectedIndexChanged
    System.Windows.Forms.MessageBox.Show("Selected index has changed.")
End Sub
private void ListObject_SelectedIndex()
{
    Worksheet vstoWorksheet = ((Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
    ListObject list1 =
        vstoWorksheet.Controls.AddListObject(
        vstoWorksheet.Range["A1", "D4"],
        "list1");

    list1.AutoSelectRows = true;
    list1.SelectedIndex = 2;
    list1.SelectedIndexChanged +=
        new EventHandler(list1_SelectedIndexChanged);
}

void list1_SelectedIndexChanged(object sender, EventArgs e)
{
    System.Windows.Forms.MessageBox.Show("Selected index has changed.");
}

.NET Framework Security

See Also

Reference

ListObject Class

ListObject Members

Microsoft.Office.Tools.Excel Namespace