ListObject.AutoSelectRows 属性

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

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

语法

声明
Property AutoSelectRows As Boolean
    Get
    Set
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 NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
            Me.Application.Worksheets(1)
        Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
                Globals.Factory.GetVstoObject(NativeWorksheet)
        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 = 
        Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]);
    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 安全性

请参见

参考

ListObject 接口

Microsoft.Office.Tools.Excel 命名空间