DataGrid.Select(Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
選取指定的資料列。
public:
void Select(int row);
public void Select (int row);
override this.Select : int -> unit
Public Sub Select (row As Integer)
參數
- row
- Int32
要選取的資料列索引。
範例
下列程式碼範例示範如何使用這個成員。
// 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.
void button11_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
myDataGrid->UnSelect( 0 );
}
// 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);
}
' Select the first row.
Private Sub button7_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button7.Click
myDataGrid.Select(0)
End Sub
' 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
' Deselect the first row.
Private Sub button11_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button11.Click
myDataGrid.UnSelect(0)
End Sub
備註
使用這個方法搭配 IsSelected 、 UnSelect 和 ResetSelection 方法來操作特定資料列的選取狀態。