Share via


DataGrid.IsSelected 方法

获取一个值,该值指示指定行是否被选定。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Function IsSelected ( _
    row As Integer _
) As Boolean
用法
Dim instance As DataGrid
Dim row As Integer
Dim returnValue As Boolean

returnValue = instance.IsSelected(row)
public bool IsSelected (
    int row
)
public:
bool IsSelected (
    int row
)
public boolean IsSelected (
    int row
)
public function IsSelected (
    row : int
) : boolean

参数

  • row
    您关注的行的编号。

返回值

如果该行被选定,则为 true;否则为 false

示例

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

   // Deselect the first row.
   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 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

DataGrid 类
DataGrid 成员
System.Windows.Forms 命名空间