BindingNavigator, classe (System.Windows.Forms)

Bibliothèque de classes .NET Framework 
BindingNavigator, classe 

Remarque : cette classe est nouvelle dans le .NET Framework version 2.0.

Représente la navigation et la manipulation de l'interface utilisateur pour les contrôles liés aux données d'un formulaire.

Espace de noms : System.Windows.Forms
Assembly : System.Windows.Forms (dans system.windows.forms.dll)

SyntaxeSyntaxe


Visual Basic (Déclaration)
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class BindingNavigator
    Inherits ToolStrip
    Implements ISupportInitialize


Visual Basic (Utilisation)
Dim instance As BindingNavigator


C#
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class BindingNavigator : ToolStrip, ISupportInitialize


C++
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class BindingNavigator : public ToolStrip, ISupportInitialize


J#
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class BindingNavigator extends ToolStrip implements ISupportInitialize


JScript
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class BindingNavigator extends ToolStrip implements ISupportInitialize
NotesNotes

Le contrôle BindingNavigator représente une direction standardisée pour parcourir et manipuler des données sur un formulaire. Dans la plupart des cas, BindingNavigator est associé à un contrôle BindingSource pour parcourir des enregistrements de données sur un formulaire et interagir avec eux. Alors la propriété BindingSource a pour valeur le composant System.Windows.Forms.BindingSource associé qui agit comme une source de données.

Par défaut, l'interface utilisateur du contrôle BindingNavigator comporte une série de boutons ToolStrip, des zones de texte et des éléments de type texte statique pour des actions liées aux données les plus courantes, telles que l'ajout de données, la suppression de données et la navigation sur des données. Chacun de ces contrôles peut être récupéré ou défini via un membre associé du contrôle BindingNavigator. De même, il existe une correspondance un-à-un avec les membres dans la classe BindingSource qui exécutent par programme les mêmes fonctions, comme indiqué dans le tableau suivant.

 

Contrôle de l'interface utilisateur

Membre BindingNavigator

Membre BindingSource

Placer en premier

MoveFirstItem

MoveFirst

Déplacer vers le haut

MovePreviousItem

MovePrevious

Position actuelle

PositionItem

Current

Count

CountItem

Count

Déplacer vers le bas

MoveNextItem

MoveNext

Placer en dernier

MoveLastItem

MoveLast

Ajouter nouveau

AddNewItem

AddNew

Supprimer

DeleteItem

RemoveCurrent

Le fait d'ajouter un contrôle BindingNavigator dans un formulaire et de le lier à une source de données, comme BindingSource établira automatiquement les relations dans cette table.

Tous les constructeurs de BindingNavigator appellent la méthode AddStandardItems pour associer le jeu standard de contrôles de l'interface utilisateur à la barre d'outils de navigation. Utilisez une des techniques suivantes pour personnaliser cette barre d'outils :

  • Créez BindingNavigator avec le constructeur BindingNavigator(Boolean) qui accepte un paramètre addStandardItems Boolean et affecte la valeur false à ce paramètre. Ajoutez ensuite les objets ToolStripItem souhaités à la collection Items.

  • Si vous souhaitez personnaliser un grand nombre de fonctions, ou si le design personnalisé est réutilisé, dérivez une classe de BindingNavigator et substituez la méthode AddStandardItems pour définir des éléments standard supplémentaires ou alternatifs.

ExempleExemple

L'exemple de code suivant montre comment utiliser un contrôle BindingNavigator pour parcourir les résultats d'une requête de base de données. Le jeu de résultats se trouve dans un DataSet qui est lié à un contrôle TextBox avec un composant BindingSource.



Visual Basic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Data.SqlClient
Imports System.Windows.Forms

' This form demonstrates using a BindingNavigator to display 
' rows from a database query sequentially.
Public Class Form1
    Inherits Form

    ' This is the BindingNavigator that allows the user
    ' to navigate through the rows in a DataSet.
    Private customersBindingNavigator As New BindingNavigator()

    ' This is the BindingSource that provides data for
    ' the Textbox control.
    Private customersBindingSource As New BindingSource()

    ' This is the TextBox control that displays the CompanyName
    ' field from the the DataSet.
    Private companyNameTextBox As New TextBox()

    Public Sub New()
        ' Set up the BindingSource component.
        Me.customersBindingNavigator.BindingSource = Me.customersBindingSource
        Me.customersBindingNavigator.Dock = DockStyle.Top
        Me.Controls.Add(Me.customersBindingNavigator)

        ' Set up the TextBox control for displaying company names.
        Me.companyNameTextBox.Dock = DockStyle.Bottom
        Me.Controls.Add(Me.companyNameTextBox)

        ' Set up the form.
        Me.Size = New Size(800, 200)
        AddHandler Me.Load, AddressOf Form1_Load
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        ' Open a connection to the database.
        ' Replace the value of connectString with a valid 
        ' connection string to a Northwind database accessible 
        ' to your system.
        Dim connectString As String = _
        "Integrated Security=SSPI;Persist Security Info=False;" + _
        "Initial Catalog=Northwind;Data Source=localhost"

        Dim connection As New SqlConnection()
        connection.ConnectionString = connectString
        connection.Open()

        ' Execute the query.
        Dim command As New SqlCommand( _
        "Select * From Customers", connection)

        Dim reader As SqlDataReader = _
        command.ExecuteReader(CommandBehavior.CloseConnection)

        ' Load the Customers result set into the DataSet.
        Dim ds As New DataSet("Northwind Customers")
        ds.Load( _
        reader, _
        LoadOption.OverwriteChanges, _
        New String() {"Customers"})

        ' Assign the DataSet as the DataSource for the BindingSource.
        Me.customersBindingSource.DataSource = ds

        ' Bind the CompanyName field to the TextBox control.
        Me.companyNameTextBox.DataBindings.Add( _
        New Binding( _
        "Text", _
        Me.customersBindingSource, _
        "CompanyName", _
        True))
    End Sub

End Class


C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using System.Windows.Forms;

// This form demonstrates using a BindingNavigator to display 
// rows from a database query sequentially.
public class Form1 : Form
{
    // This is the BindingNavigator that allows the user
    // to navigate through the rows in a DataSet.
    BindingNavigator customersBindingNavigator = new BindingNavigator();

    // This is the BindingSource that provides data for
    // the Textbox control.
    BindingSource customersBindingSource = new BindingSource();

    // This is the TextBox control that displays the CompanyName
    // field from the the DataSet.
    TextBox companyNameTextBox = new TextBox();

    public Form1()
    {
        // Set up the BindingSource component.
        this.customersBindingNavigator.BindingSource = this.customersBindingSource;
        this.customersBindingNavigator.Dock = DockStyle.Top;
        this.Controls.Add(this.customersBindingNavigator);

        // Set up the TextBox control for displaying company names.
        this.companyNameTextBox.Dock = DockStyle.Bottom;
        this.Controls.Add(this.companyNameTextBox);

        // Set up the form.
        this.Size = new Size(800, 200);
        this.Load += new EventHandler(Form1_Load);
    }

    void Form1_Load(object sender, EventArgs e)
    {   
        // Open a connection to the database.
        // Replace the value of connectString with a valid 
        // connection string to a Northwind database accessible 
        // to your system.
        string connectString = 
            "Integrated Security=SSPI;Persist Security Info=False;" +
            "Initial Catalog=Northwind;Data Source=localhost";
        SqlConnection connection = new SqlConnection();
        connection.ConnectionString = connectString;
        connection.Open();

        // Execute the query.
        SqlCommand command = new SqlCommand(
            "Select * From Customers", connection);
        SqlDataReader reader = command.ExecuteReader(
            CommandBehavior.CloseConnection);

        // Load the Customers result set into the DataSet.
        DataSet ds = new DataSet("Northwind Customers");
        ds.Load(
            reader, 
            LoadOption.OverwriteChanges, 
            new string[] { "Customers" });

        // Assign the DataSet as the DataSource for the BindingSource.
        this.customersBindingSource.DataSource = ds;

        // Bind the CompanyName field to the TextBox control.
        this.companyNameTextBox.DataBindings.Add(
            new Binding("Text", 
            this.customersBindingSource, 
            "CompanyName", 
            true));
    }
}


C++
#using <System.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.EnterpriseServices.dll>
#using <System.Transactions.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Data::SqlClient;
using namespace System::Windows::Forms;

// This form demonstrates using a BindingNavigator to display
// rows from a database query sequentially.
public ref class Form1 : public Form
{
    // This is the BindingNavigator that allows the user
    // to navigate through the rows in a DataSet.
    BindingNavigator^ customersBindingNavigator;

    // This is the BindingSource that provides data for
    // the Textbox control.
    BindingSource^ customersBindingSource;

    // This is the TextBox control that displays the CompanyName
    // field from the the DataSet.
    TextBox^ companyNameTextBox;

public:
    Form1()
    {
        // Set up the BindingSource component.
        this->customersBindingSource = gcnew BindingSource();
        this->companyNameTextBox = gcnew TextBox();
        this->customersBindingNavigator = gcnew BindingNavigator();
        this->customersBindingNavigator->BindingSource =
            this->customersBindingSource;
        this->customersBindingNavigator->Dock = DockStyle::Top;
        this->Controls->Add(this->customersBindingNavigator);

        // Set up the TextBox control for displaying company names.
        this->companyNameTextBox->Dock = DockStyle::Bottom;
        this->Controls->Add(this->companyNameTextBox);

        // Set up the form.
        this->Size = System::Drawing::Size(800, 200);
        this->Load += gcnew EventHandler(this, &Form1::Form1_Load);
    }

private:
    void Form1_Load(Object^ sender, EventArgs^ e)
    {
        // Open a connection to the database.
        // Replace the value of connectString with a valid
        // connection string to a Northwind database accessible
        // to your system.
        String^ connectString =
            "Integrated Security=SSPI;Persist Security Info=False;" +
            "Initial Catalog=Northwind;Data Source=localhost";
        SqlConnection^ connection = gcnew SqlConnection();
        connection->ConnectionString = connectString;
        connection->Open();

        // Execute the query.
        SqlCommand^ command = gcnew SqlCommand(
            "Select * From Customers", connection);
        SqlDataReader^ reader = command->ExecuteReader(
            CommandBehavior::CloseConnection);

        // Load the Customers result set into the DataSet.
        DataSet^ ds = gcnew DataSet("Northwind Customers");
        ds->Load(reader, LoadOption::OverwriteChanges,
            gcnew array<String^> {"Customers"});

        // Assign the DataSet as the DataSource for the
        // BindingSource.
        this->customersBindingSource->DataSource = ds->Tables[0];

        // Bind the CompanyName field to the TextBox control.
        this->companyNameTextBox->DataBindings->Add(gcnew Binding("Text",
            this->customersBindingSource, "CompanyName", true));
    }
};
Hiérarchie d'héritageHiérarchie d'héritage
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
           System.Windows.Forms.ToolStrip
            System.Windows.Forms.BindingNavigator
Sécurité des threadsSécurité des threads
Les membres statiques publics (Shared en Visual Basic) de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.
Plates-formesPlates-formes

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

Informations de versionInformations de version

.NET Framework

Prise en charge dans : 2.0
Voir aussiVoir aussi

Ces informations proviennent du site de http://msdn2.microsoft.com
Source de cette page : http://msdn2.microsoft.com/fr-fr/library/system.windows.forms.bindingnavigator.aspx

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

9 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-4338
Document créé le 14/10/06 23:50, dernière modification le Vendredi 17 Juin 2011, 12:11
Source du document imprimé : http://www.gaudry.be/dotnet-rf-system.windows.forms.bindingnavigator.html Document affiché 1 fois ce mois de Juin.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,61 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Les rêves sont les clés pour sortir de nous-mêmes.

Georges Rodenbach
 
l'infobrol
Nous sommes le Vendredi 01 Juin 2012, 04:57, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)