This documentation is archived and is not being maintained.

DataGrid.IsSelected Method

Gets a value indicating whether a specified row is selected.

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

public bool IsSelected (
	int row
)
public boolean IsSelected (
	int row
)
public function IsSelected (
	row : int
) : boolean
Not applicable.

Parameters

row

The number of the row you are interested in.

Return Value

true if the row is selected; otherwise, false.

Use this method with the Select, UnSelect, and ResetSelection methods to manipulate the selection state of a particular row.

Windows Mobile 2003 for Pocket PC, Windows Mobile 2003 for Smartphone, Windows CE Platform Note: On the .NET Compact Framework, this member throws a Exception when the grid has no active table style.

The following code example demonstrates the use of this member.

// 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);
}

// 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);
    }
} //button8_Click

// Deselect the first row.
private void button11_Click(Object sender, EventArgs e)
{
    myDataGrid.UnSelect(0);
} //button11_Click

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, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Show: