Udostępnij za pośrednictwem


Understanding ListObject Column and Row Order Persistence

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

When you bind data to a ListObject control that was added to a document at design time, Visual Studio Tools for Office keeps track of the column and row order whenever the workbook is saved. If a user moves the ListObject columns or rows during run time, the new order is preserved the next time the workbook is opened and the ListObject control binds to the data source again.

How Column and Row Order Is Persisted

When you save a workbook that contains a ListObject bound to data, the column and row order gets stored in the workbook in a custom document property.

The name of the property is determined by using a hash code for the combined name of the worksheet and list object. For example, the custom document property name for a ListObject control named List1 on Sheet1 would be ___2387CEF09___0. If the value of this property exceeds 255 characters in length, another custom document property is created with the next sequential number appended; for example, ___2387CEF09___1, ___2387CEF09___2, and so on.

The value for the custom document property contains the column names and row numbers. For example, if the ListObject is made up of four rows and two columns, named LastName and FirstName, the value for the property would be FirstName*LastName%1*2*3*4. If the user moves row three above row two, the value will be changed to FirstName*LastName%1*3*2*4 when the workbook is saved.

The next time the workbook is opened, the ListObject reads the information from the custom document properties and maintains the order of the rows and columns when the data is loaded.

How to Restore Column and Row Order.

If you want to restore the ListObject to its original column and row order, you can call the ResetPersistedBindingInformation method. This method removes the custom document properties related to the column and row order of specified ListObject. Call this method from the Shutdown event of the Workbook if you do not want to preserve the column and row order of the ListObject.

See Also

Tasks

How to: Map ListObject Columns to Data

Concepts

ListObject Control

Other Resources

Excel Host Controls