Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
1 out of 1 rated this helpful - Rate this topic

BindingSource.Current Property

Gets the current item in the list.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public Object Current { get; }
/** @property */
public Object get_Current ()

public function get Current () : Object

Not applicable.

Property Value

An Object that represents the current item in the underlying list represented by the List property, or a null reference (Nothing in Visual Basic) if the list has no items.

Use the Current property to access the current item, but use the List property to get the entire list. To determine the type of the current object, use the GetType, or ToString methods.

To change the current item, set the Position property to a new integral value, or use one of the navigation methods such as MoveNext.

The following code example demonstrates the Current property. 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;
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.