ListObject.AutoSelectRows 属性 (2007 system)

更新:2007 年 11 月

获取或设置一个值,该值指示在 SelectedIndex 发生更改时是否选择整行。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v9.0(在 Microsoft.Office.Tools.Excel.v9.0.dll 中)

语法

声明
Public Property AutoSelectRows As Boolean
用法
Dim instance As ListObject
Dim value As Boolean

value = instance.AutoSelectRows

instance.AutoSelectRows = value
public bool AutoSelectRows { get; set; }

属性值

类型:System.Boolean

如果选择整行,则为 true;否则为 false。默认值为 false。

备注

当此属性设置为 true 时,则会选择与 SelectedIndex 相对应的 ListObject 控件用户界面中的整行。

示例

下面的代码示例在当前的工作表上创建一个 ListObject。它使用 SelectedIndex 和 AutoSelectRows 属性选择第二行并指定在用户单击某一行时将选择整行。该代码示例还为在选择新行时显示消息框的 SelectedIndexChanged 事件创建事件处理程序。

此版本针对的是文档级自定义项。

    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.");
}

此版本针对的是应用程序级外接程序。

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.");
}

权限

另请参见

参考

ListObject 类

ListObject 成员

Microsoft.Office.Tools.Excel 命名空间