Export (0) Print
Expand All

BindingSource.MoveNext Method

Moves to the next item in the list.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

'Declaration
Public Sub MoveNext

Changes the current value of the Position property to the next item in the underlying data source.

The following code example demonstrates the MoveNext, MoveFirst, Current, and Position members. To run this example, paste the code into a form that imports the System.Drawing.Drawing2D namespace and contains a BindingSource named BindingSource1 and a button named button1. Associate the Form1_Load and Form1_Paint methods with the Load and Paint events for the form, and associate the button1_click method with the Click event for button1. Visual Basic users will need to add a reference to System.Data.dll.

Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
        Handles Me.Load

        ' Set the data source to the Brush type and populate 
        ' BindingSource1 with some brushes.
        BindingSource1.DataSource = GetType(System.Drawing.Brush)
        BindingSource1.Add(New TextureBrush(New Bitmap(GetType(Button), _
            "Button.bmp")))
        BindingSource1.Add(New HatchBrush(HatchStyle.Cross, Color.Red))
        BindingSource1.Add(New SolidBrush(Color.Blue))

    End Sub 



    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
         Handles button1.Click

        ' If you are not at the end of the list, move to the next item 
        ' in the BindingSource. 
        If BindingSource1.Position + 1 < BindingSource1.Count Then
            BindingSource1.MoveNext()

            ' Otherwise, move back to the first item. 
        Else
            BindingSource1.MoveFirst()
        End If 

        ' Force the form to repaint. 
        Me.Invalidate()

    End Sub 


    Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)

        ' Get the current item in the BindingSource. 
        Dim item As Brush = CType(BindingSource1.Current, Brush)

        ' If the current type is a TextureBrush, fill an ellipse. 
        If item.GetType().Equals(GetType(TextureBrush)) Then
            e.Graphics.FillEllipse(item, _
            e.ClipRectangle)

            ' If the current type is a HatchBrush, fill a triangle. 
        ElseIf item.GetType().Equals(GetType(HatchBrush)) Then
            e.Graphics.FillPolygon(item, New Point() _
             {New Point(0, 0), New Point(0, 200), New Point(200, 0)})

            ' Otherwise, fill a rectangle. 
        Else
            e.Graphics.FillRectangle(item, e.ClipRectangle)
        End If 

    End Sub

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft