Ler en inglés

Compartir por


DesignerDataSourceView Clase

Definición

Actúa como clase base para las clases de vista de origen de datos en tiempo de diseño.

C#
public abstract class DesignerDataSourceView
Herencia
DesignerDataSourceView
Derivado

Ejemplos

En el ejemplo de código siguiente se muestra cómo crear un objeto personalizado DesignerDataSourceView junto con una clase personalizada IDataSourceViewSchema y dos clases personalizadas IDataSourceFieldSchema .

Este ejemplo forma parte de un ejemplo más grande para la DataSourceDesigner clase .

C#
// A design-time data source view
public class CustomDesignDataSourceView : DesignerDataSourceView
{
    private ArrayList _data = null;

    public CustomDesignDataSourceView(
        CustomDataSourceDesigner owner, string viewName)
        : base(owner, viewName)
    {}

    // Get data for design-time display
    public override IEnumerable GetDesignTimeData(
        int minimumRows, out bool isSampleData)
    {
        if (_data == null)
        {
            // Create a set of design-time fake data
            _data = new ArrayList();
            for (int i = 1; i <= minimumRows; i++)
            {
                _data.Add(new BookItem("ID_" + i.ToString(),
                    "Design-Time Title 0" + i.ToString()));
            }
        }
        isSampleData = true;
        return _data as IEnumerable;
    }

    public override IDataSourceViewSchema Schema
    {
        get { return new BookListViewSchema(); }
    }

    // Allow getting the record count
    public override bool CanRetrieveTotalRowCount
    {
        get { return true; }
    }
    // Do not allow deletions
    public override bool CanDelete
    {
        get { return false; }
    }
    // Do not allow insertions
    public override bool CanInsert
    {
        get { return false; }
    }
    // Do not allow updates
    public override bool CanUpdate
    {
        get { return false; }
    }
    // Do not allow paging
    public override bool CanPage
    {
        get { return false; }
    }
    // Do not allow sorting
    public override bool CanSort
    {
        get { return false; }
    }
}
C#
// A custom View Schema class
public class BookListViewSchema : IDataSourceViewSchema
{
    public BookListViewSchema()
    { }

    // The name of this View Schema
    public string Name
    {
        get { return "BookList"; }
    }

    // Build a Field Schema array
    public IDataSourceFieldSchema[] GetFields()
    {
        IDataSourceFieldSchema[] fields = new IDataSourceFieldSchema[2];
        fields[0] = new CustomIDFieldSchema();
        fields[1] = new CustomTitleFieldSchema();
        return fields;
    }
    // There are no child views, so return null
    public IDataSourceViewSchema[] GetChildren()
    {
        return null;
    }
}

// A custom Field Schema class for ID
public class CustomIDFieldSchema : IDataSourceFieldSchema
{
    public CustomIDFieldSchema()
    { }

    // Name is ID
    public string Name
    {
        get { return "ID"; }
    }
    // Data type is string
    public Type DataType
    {
        get { return typeof(string); }
    }
    // This is not an Identity field
    public bool Identity
    {
        get { return false; }
    }
    // This field is read only
    public bool IsReadOnly
    {
        get { return true; }
    }
    // This field is unique
    public bool IsUnique
    {
        get { return true; }
    }
    // This field can't be longer than 20
    public int Length
    {
        get { return 20; }
    }
    // This field can't be null
    public bool Nullable
    {
        get { return false; }
    }
    // This is a Primary Key
    public bool PrimaryKey
    {
        get { return true; }
    }

    // These properties do not apply
    public int Precision
    {
        get { return -1; }
    }
    public int Scale
    {
        get { return -1; }
    }
}

// A custom Field Schema class for Title
public class CustomTitleFieldSchema : IDataSourceFieldSchema
{
    public CustomTitleFieldSchema()
    { }

    // Name is Title
    public string Name
    {
        get { return "Title"; }
    }
    // Type is string
    public Type DataType
    {
        get { return typeof(string); }
    }
    // This is not an Identity field
    public bool Identity
    {
        get { return false; }
    }
    // This field is not read only
    public bool IsReadOnly
    {
        get { return false; }
    }
    // This field is not unique
    public bool IsUnique
    {
        get { return false; }
    }
    // This field can't be longer than 100
    public int Length
    {
        get { return 100; }
    }
    // This field can't be null
    public bool Nullable
    {
        get { return false; }
    }
    // This is not the Primary Key
    public bool PrimaryKey
    {
        get { return false; }
    }

    // These properties do not apply
    public int Precision
    {
        get { return -1; }
    }
    public int Scale
    {
        get { return -1; }
    }
}

Notas a los implementadores

Cuando hereda de la DesignerDataSourceView clase , debe invalidar el GetDesignTimeData(Int32, Boolean) método para crear datos de ejemplo que se ajusten a la Schema propiedad o para devolver datos reales del origen de datos.

Constructores

DesignerDataSourceView(IDataSourceDesigner, String)

Inicializa una nueva instancia de la clase DesignerDataSourceView utilizando el diseñador de origen de datos y el nombre de la vista especificados.

Propiedades

CanDelete

Obtiene un valor que indica si el objeto DataSourceView asociado al objeto DataSourceControl actual admite el método ExecuteDelete(IDictionary, IDictionary).

CanInsert

Obtiene un valor que indica si el objeto DataSourceView asociado al objeto DataSourceControl actual admite el método ExecuteInsert(IDictionary).

CanPage

Obtiene un valor que indica si el objeto DataSourceView asociado al objeto DataSourceControl actual admite paginación de los datos que recupera el método ExecuteSelect(DataSourceSelectArguments).

CanRetrieveTotalRowCount

Obtiene un valor que indica si el objeto DataSourceView asociado al objeto DataSourceControl actual admite la recuperación del número total de filas de datos en lugar de los propios datos.

CanSort

Obtiene un valor que indica si el objeto DataSourceView asociado al objeto DataSourceControl actual admite una vista ordenada del origen de datos subyacente.

CanUpdate

Obtiene un valor que indica si el objeto DataSourceView asociado al objeto DataSourceControl actual admite el método ExecuteUpdate(IDictionary, IDictionary, IDictionary).

DataSourceDesigner

Obtiene una referencia al diseñador que creó este control DesignerDataSourceView.

Name

Obtiene el nombre de la vista que se proporcionó cuando se creó esta instancia de la clase DesignerDataSourceView.

Schema

Obtiene un esquema que describe la vista del origen de datos que representa este objeto de vista.

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetDesignTimeData(Int32, Boolean)

Genera datos en tiempo de diseño que coinciden con el esquema del control de origen de datos asociado utilizando el número de filas especificado e indica si los datos devueltos son un ejemplo o son datos reales.

GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a

Produto Versións
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Consulte también