ListObject.SelectionChange Event
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs when the selection changes inside the ListObject control.
public:
event Microsoft::Office::Interop::Excel::DocEvents_SelectionChangeEventHandler ^ SelectionChange;
event Microsoft.Office.Interop.Excel.DocEvents_SelectionChangeEventHandler SelectionChange;
member this.SelectionChange : Microsoft.Office.Interop.Excel.DocEvents_SelectionChangeEventHandler
Event SelectionChange As DocEvents_SelectionChangeEventHandler
Event Type
Examples
The following code example creates a ListObject and then creates an event handler for the SelectionChange event. To test the event handler, select a cell in the ListObject and then select a different cell in the ListObject.
This version is for a document-level customization.
private void ListObject_SelectionChange()
{
Microsoft.Office.Tools.Excel.ListObject list1 =
this.Controls.AddListObject(
this.Range["A1", "C4"], "list1");
list1.SelectionChange += new Microsoft.Office.Interop.
Excel.DocEvents_SelectionChangeEventHandler(
list1_SelectionChange);
}
void list1_SelectionChange(Microsoft.Office.Interop.Excel.Range Target)
{
MessageBox.Show("The selection in the list object has changed.");
}
WithEvents SelectionChangeList As Microsoft.Office.Tools.Excel.ListObject
Private Sub ListObject_SelectionChange()
SelectionChangeList = Me.Controls.AddListObject( _
Me.Range("A1", "C4"), "SelectionChangeList")
End Sub
Sub List1_SelectionChange(ByVal Target As _
Microsoft.Office.Interop.Excel.Range) _
Handles SelectionChangeList.SelectionChange
MessageBox.Show("The selection in the list object has changed.")
End Sub
This version is for an application-level add-in.
private void ListObject_SelectionChange()
{
Worksheet vstoWorksheet =
Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]); ;
ListObject list1 =
vstoWorksheet.Controls.AddListObject(
vstoWorksheet.Range["A1", "C4"], "list1");
list1.SelectionChange += new
Excel.DocEvents_SelectionChangeEventHandler(
list1_SelectionChange);
}
void list1_SelectionChange(Excel.Range Target)
{
System.Windows.Forms.MessageBox.Show("The selection in the list object has changed.");
}
WithEvents SelectionChangeList As ListObject
Private Sub ListObject_SelectionChange()
Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
Me.Application.Worksheets(1)
Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
Globals.Factory.GetVstoObject(NativeWorksheet)
SelectionChangeList = vstoWorksheet.Controls.AddListObject( _
vstoWorksheet.Range("A1", "C4"), "SelectionChangeList")
End Sub
Sub List1_SelectionChange(ByVal Target As _
Microsoft.Office.Interop.Excel.Range) _
Handles SelectionChangeList.SelectionChange
System.Windows.Forms.MessageBox.Show( _
"The selection in the list object has changed.")
End Sub
Remarks
This event is raised when any selected range inside the ListObject changes.
This event is not raised when focus moves from inside a ListObject control to outside of the ListObject control. It is raised when focus moves from outside a ListObject control to the ListObject control.