Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

ListObjectChangeHandler Delegate

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Represents the method that will handle the Change event of a ListObject.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
public delegate void ListObjectChangeHandler(
	Range targetRange,
	ListRanges changedRanges
)

Parameters

targetRange
Type: Microsoft.Office.Interop.Excel.Range

The Range that the change occurred in.

changedRanges
Type: Microsoft.Office.Tools.Excel.ListRanges

The areas of the ListObject that contain changes.

When you create a ListObjectChangeHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler method is called whenever the event occurs unless you remove the delegate. For more information about delegates, see Events and Delegates.

The following code example creates a ListObject and a Change event handler. To raise the Change event, add text to one of the cells in the ListObject and then press ENTER.

private void ListObject_Change()
{
    Microsoft.Office.Tools.Excel.ListObject list1 = 
        this.Controls.AddListObject(
        this.Range["A1", "C4"], "list1");
    list1.Change += new Microsoft.Office.Tools.Excel.
        ListObjectChangeHandler(list1_Change);
}

void list1_Change(Microsoft.Office.Interop.Excel.Range 
    targetRange, Microsoft.Office.Tools.Excel.ListRanges 
    changedRanges)
{
    string cellAddress = targetRange.get_Address(
        Excel.XlReferenceStyle.xlA1 
        );

    switch (changedRanges)
    {
        case Microsoft.Office.Tools.Excel.ListRanges.DataBodyRange:
            MessageBox.Show("The cells at range " + cellAddress +
                " in the data body changed.");
            break;
        case Microsoft.Office.Tools.Excel.ListRanges.HeaderRowRange:
            MessageBox.Show("The cells at range " + cellAddress +
                " in the header row changed.");
            break;
        case Microsoft.Office.Tools.Excel.ListRanges.TotalsRowRange:
            MessageBox.Show("The cells at range " + cellAddress +
                " in the totals row changed.");
            break;
        default:
            MessageBox.Show("The cells at range " + cellAddress +
                " changed.");
            break;
    }
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.