NamedRange control
The NamedRange control is a range that has a unique name, exposes events, and can be bound to data. For more information, see Excel object model overview.
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Excel. For more information, see Features available by Office application and project type.
Create the control
You can add NamedRange controls to a Microsoft Office Excel worksheet at design time or at run time in document-level projects.
You can add NamedRange controls to a worksheet at run time in a VSTO Add-in. For more information, see How to: Add NamedRange controls to worksheets.
Note
By default, dynamically created named ranges are not persisted in the worksheet as host controls when the worksheet is closed. For more information, see Add controls to Office documents at run time.
NamedRange controls can only consist of ranges on specific sheets. NamedRange controls cannot have relative names that apply to all sheets, and they cannot consist of ranges that span two or more worksheets in a workbook (3-D ranges).
Bind data to the control
A named range would appear to be a good candidate for complex data binding since it can have many cells; however, a range is merely a collection of cells that cannot be easily mapped to a particular column from a dataset. Therefore, NamedRange controls only support simple data binding. The ListObject control can be used for complex data binding. For more information, see ListObject control.
The NamedRange control can be bound to a data source using the DataBindings properties. The default data binding property of the NamedRange control is Value2.
If the data in the bound dataset is updated through any mechanism, the NamedRange control reflects the changes.
Formatting
Formatting that can be applied to a Range can be applied to a NamedRange control. This includes borders, fonts, number formats, and styles.
Rename the control
When you add a NamedRange control to your worksheet from the Toolbox, Visual Studio automatically generates a name for the control. You can change the name in the Properties window.
Events
The following events are available for the NamedRange control:
Related content
- Automate Excel by using extended objects
- Office development samples and walkthroughs
- Bind data to controls in Office solutions
- Extend Word documents and Excel workbooks in VSTO Add-ins at run time
- Controls on Office documents
- Add controls to Office documents at run time
- How to: Add NamedRange controls to worksheets
- How to: Resize NamedRange controls
- Bind data to controls in Office solutions
- Walkthrough: Program against events of a NamedRange control
- Programmatic limitations of host items and host controls