Adds an existing item to the internal list.
Namespace:
System.Windows.Forms
Assembly:
System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
Public Overridable Function Add ( _
value As Object _
) As Integer
Dim instance As BindingSource
Dim value As Object
Dim returnValue As Integer
returnValue = instance.Add(value)
public virtual int Add(
Object value
)
public:
virtual int Add(
Object^ value
)
public function Add(
value : Object
) : int
Return Value
Type:
System..::.Int32The zero-based index at which value was added to the underlying list represented by the List property.
Implements
IList..::.Add(Object)
The Add method refers the call to the underlying list's Add method.
The internal list must contain homogenous types. If the DataSource property has not already been set, then the first object added to the list defines the type for the list.
This method raises the ListChanged event.
The following code example how to use the Add method. To run this example, paste the code into a Windows Form, and call the PopulateBindingSourceWithFonts method from the form's constructor.
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
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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
.NET Compact Framework
Supported in: 3.5, 2.0
Reference