BindingSource.Current BindingSource.Current BindingSource.Current BindingSource.Current Property

Définition

Obtient l'élément en cours dans la liste.Gets the current item in the list.

public:
 property System::Object ^ Current { System::Object ^ get(); };
[System.ComponentModel.Browsable(false)]
public object Current { get; }
member this.Current : obj
Public ReadOnly Property Current As Object

Valeur de propriété

Un Object qui représente l'élément actuel dans la liste sous-jacente représentée par la propriété List, ou null si la liste n'a pas d'éléments.An Object that represents the current item in the underlying list represented by the List property, or null if the list has no items.

Exemples

L’exemple de code suivant illustre Current la propriété.The following code example demonstrates the Current property. Pour exécuter cet exemple, collez le code dans un formulaire et appelez PopulateBindingSourceWithFonts la méthode à partir de Load la méthode de gestion des événements du formulaire.To run this example, paste the code into a form and call the PopulateBindingSourceWithFonts method from the form's Load event handling method.

public BindingSource bindingSource1 = new BindingSource();
TextBox box1 = new TextBox();

private void PopulateBindingSourceWithFonts()
{
    bindingSource1.CurrentChanged += new EventHandler(bindingSource1_CurrentChanged);
    bindingSource1.Add(new Font(FontFamily.Families[2], 8.0F));
    bindingSource1.Add(new Font(FontFamily.Families[4], 9.0F));
    bindingSource1.Add(new Font(FontFamily.Families[6], 10.0F));
    bindingSource1.Add(new Font(FontFamily.Families[8], 11.0F));
    bindingSource1.Add(new Font(FontFamily.Families[10], 12.0F));
    DataGridView view1 = new DataGridView();
    view1.DataSource = bindingSource1;
    view1.AutoGenerateColumns = true;
    view1.Dock = DockStyle.Top;
    this.Controls.Add(view1);
    box1.Dock = DockStyle.Bottom;
    box1.Text = "Sample Text";
    this.Controls.Add(box1);
    box1.DataBindings.Add("Text", bindingSource1, "Name");
    view1.Columns[7].DisplayIndex = 0;
    
}

void bindingSource1_CurrentChanged(object sender, EventArgs e)
{
    box1.Font = (Font)bindingSource1.Current;
}
Private WithEvents bindingSource1 As New BindingSource()
Private box1 As New TextBox()


Private Sub PopulateBindingSourceWithFonts()
  
    bindingSource1.Add(New Font(FontFamily.Families(2), 8.0F))
    bindingSource1.Add(New Font(FontFamily.Families(4), 9.0F))
    bindingSource1.Add(New Font(FontFamily.Families(6), 10.0F))
    bindingSource1.Add(New Font(FontFamily.Families(8), 11.0F))
    bindingSource1.Add(New Font(FontFamily.Families(10), 12.0F))
    Dim view1 As New DataGridView()
    view1.DataSource = bindingSource1
    view1.AutoGenerateColumns = True
    view1.Dock = DockStyle.Top
    Me.Controls.Add(view1)
    box1.Dock = DockStyle.Bottom
    box1.Text = "Sample Text"
    Me.Controls.Add(box1)
    view1.Columns("Name").DisplayIndex = 0
    box1.DataBindings.Add("Text", bindingSource1, "Name")
    
End Sub
 
Sub bindingSource1_CurrentChanged(ByVal sender As Object, ByVal e As EventArgs) _
    Handles bindingSource1.CurrentChanged
    box1.Font = CType(bindingSource1.Current, Font)
End Sub

Remarques

Utilisez la Current propriété pour accéder à l’élément actuel, mais utilisez List la propriété pour récupérer la liste entière.Use the Current property to access the current item, but use the List property to get the entire list. Pour déterminer le type de l’objet actuel, utilisez les GetTypeméthodes, ToString ou.To determine the type of the current object, use the GetType, or ToString methods.

Pour modifier l’élément actuel, affectez Position à la propriété une nouvelle valeur intégrale ou utilisez l’une des méthodes de navigation MoveNexttelles que.To change the current item, set the Position property to a new integral value, or use one of the navigation methods such as MoveNext.

S’applique à

Voir aussi