Export (0) Print
Expand All

DataGrid.Select Method

Selects a specified row.

Overload List

Selects a specified row.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub Select(Integer)
[C#] public void Select(int);
[C++] public: void Select(int);
[JScript] public function Select(int);

Inherited from Control.

[Visual Basic] Overloads Public Sub Select()
[C#] public void Select();
[C++] public: void Select();
[JScript] public function Select();

Inherited from Control.

[Visual Basic] Overloads Protected Overridable Sub Select(Boolean, Boolean)
[C#] protected virtual void Select(bool, bool);
[C++] protected: virtual void Select(bool, bool);
[JScript] protected function Select(Boolean, Boolean);

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Select. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' Select the first row.
Private Sub button7_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button7.Click
    myDataGrid.Select(0)
End Sub 'button7_Click

' Check if the first row is selected.
Private Sub button8_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button8.Click
    If myDataGrid.IsSelected(0) Then
        MessageBox.Show("Row selected", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    Else
        MessageBox.Show("Row not selected", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    End If
End Sub 'button8_Click

' Deselect the first row.
Private Sub button11_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button11.Click
    myDataGrid.UnSelect(0)
End Sub 'button11_Click


[C#] 
// Select the first row.
private void button7_Click(object sender, EventArgs e)
{
   myDataGrid.Select(0);
}
// Check if the first row is selected.
private void button8_Click(object sender, EventArgs e)
{         
   if(myDataGrid.IsSelected(0))
   {
      MessageBox.Show("Row selected",
         "Message",   MessageBoxButtons.OK,
         MessageBoxIcon.Exclamation);
   }
   else
   {
      MessageBox.Show("Row not selected",
         "Message",   MessageBoxButtons.OK,
         MessageBoxIcon.Exclamation);
   }         
}
// Deselect the first row.
private void button11_Click(object sender, EventArgs e)
{
   myDataGrid.UnSelect(0);
}

[C++] 
private:
    // Select the first row.
    void button7_Click(Object* /*sender*/, EventArgs* /*e*/) {
        myDataGrid->Select(0);
    }

private:
    // Check if the first row is selected.
    void button8_Click(Object* /*sender*/, EventArgs* /*e*/) {
        if (myDataGrid->IsSelected(0)) {
            MessageBox::Show(S"Row selected",
                S"Message",   MessageBoxButtons::OK,
                MessageBoxIcon::Exclamation);
        } else {
            MessageBox::Show(S"Row not selected",
                S"Message",   MessageBoxButtons::OK,
                MessageBoxIcon::Exclamation);
        }
    }
    // Deselect the first row.
    void button11_Click(Object* /*sender*/, EventArgs* /*e*/) {
        myDataGrid->UnSelect(0);
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DataGrid Class | DataGrid Members | System.Windows.Forms Namespace

Show:
© 2014 Microsoft