DataSourceControl.GetViewNames 方法

定义

获取名称的集合,表示与 DataSourceControl 控件关联的 DataSourceView 对象的列表。Gets a collection of names, representing the list of DataSourceView objects associated with the DataSourceControl control.

protected:
 virtual System::Collections::ICollection ^ GetViewNames();
protected virtual System.Collections.ICollection GetViewNames ();
abstract member GetViewNames : unit -> System.Collections.ICollection
override this.GetViewNames : unit -> System.Collections.ICollection
Protected Overridable Function GetViewNames () As ICollection

返回

ICollection,包含与 DataSourceControl 关联的 DataSourceView 对象的名称。An ICollection that contains the names of the DataSourceView objects associated with the DataSourceControl.

实现

示例

下面的代码示例演示如何扩展DataSourceControl类的类可以重写默认实现 (返回null) 以提供视图名称的集合。The following code example demonstrates how a class that extends the DataSourceControl class can override the default implementation, which returns null, to provide a collection of view names. CsvDataSource类只支持一个视图, 因此将返回一个具有默认视图名称的元素的集合。The CsvDataSource class only supports one view; therefore, a collection of one element with the default view name is returned. 此代码示例是为DataSourceControl类提供的更大示例的一部分。This code example is part of a larger example provided for the DataSourceControl class.

    // The ListSourceHelper class calls GetList, which
    // calls the DataSourceControl.GetViewNames method.
    // Override the original implementation to return
    // a collection of one element, the default view name.
    protected override ICollection GetViewNames() {
        ArrayList al = new ArrayList(1);
        al.Add(CsvDataSourceView.DefaultViewName);
        return al as ICollection;
    }
}
   ' The ListSourceHelper class calls GetList, which
   ' calls the DataSourceControl.GetViewNames method.
   ' Override the original implementation to return
   ' a collection of one element, the default view name.
   Protected Overrides Function GetViewNames() As ICollection
      Dim al As New ArrayList(1)
      al.Add(CsvDataSourceView.DefaultViewName)
      Return CType(al, ICollection)
   End Function 'GetViewNames

End Class

注解

名称集合是允许的一组值, 可以传递GetView给方法。 ICollectionThe ICollection collection of names is the allowable set of values that can be passed to the GetView method.

类用于DataSourceControl类的IListSource实现, 同时检查和调用的方法,以确定数据源控件是否与一个关联IListSource.GetList GetViewNames ListSourceHelper IListSource.ContainsListCollection或多个数据源视图。The ListSourceHelper class, which is used for the DataSourceControl class's IListSource implementation, checks the GetViewNames method for both the IListSource.ContainsListCollection and IListSource.GetList calls to determine whether the data source control is associated with one or more data source views. 如果GetViewNames返回false IListSource.ContainsListCollection IListSource.GetList null, 这是方法的默认实现, 则返回并返回。 nullIf GetViewNames returns null, which is the default implementation of the method, IListSource.ContainsListCollection returns false and IListSource.GetList returns null.

备注

类的默认实现返回nullDataSourceControlThe DataSourceControl class's default implementation returns null. 如果扩展DataSourceControl类, 请GetViewNames重写方法以返回视图名称的集合。If you extend the DataSourceControl class, override the GetViewNames method to return a collection of view names.

适用于

另请参阅