Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MoveFirst Method

BindingSource::MoveFirst Method

Moves to the first item in the list.

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

public:
void MoveFirst()

Changes the current value of the Position property to 0, the first 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.

        void Form1_Load(Object^ sender, EventArgs^ e)
        {
            // Set the data source to the Brush type and populate 
            // bindingSource1; with some brushes.
            bindingSource1->DataSource = System::Drawing::Brush::typeid;
            bindingSource1->Add(
                gcnew TextureBrush(gcnew Bitmap(Button::typeid, "Button.bmp")));
            bindingSource1->Add(gcnew HatchBrush(HatchStyle::Cross, Color::Red));
            bindingSource1->Add(gcnew SolidBrush(Color::Blue));
        }


    private:
        void moveNextButton_Click(Object^ sender, EventArgs^ e)
        {
            // If you are not at the end of the list, move to the next item 
            // in the BindingSource. 
            if (bindingSource1->Position + 1 < bindingSource1->Count)
            {
                bindingSource1->MoveNext();
            }
            // Otherwise, move back to the first item. 
            else
            {
                bindingSource1->MoveFirst();
            }
            // Force the form to repaint. 
            this->Invalidate();
        }

        void Form1_Paint(Object^ sender, PaintEventArgs^ e)
        {
            // Get the current item in the BindingSource.
            Brush^ item = (Brush^) bindingSource1->Current;

            // If the current type is a TextureBrush, fill an ellipse. 
            if (item->GetType() == TextureBrush::typeid)
            {
                e->Graphics->FillEllipse(item,e->ClipRectangle);
            }
            // If the current type is a HatchBrush, fill a triangle. 
            else if (item->GetType() == HatchBrush::typeid)
            {

                e->Graphics->FillPolygon(item, 
                    gcnew array<Point> {*gcnew Point(0, 0),
                    *gcnew Point(0, 200),
                    *gcnew Point(200, 0)});
            }
            // Otherwise, fill a rectangle. 
            else
            {
                e->Graphics->FillRectangle(
                    (Brush^)bindingSource1->Current, e->ClipRectangle);
            }
        }

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft