DataGridView.SelectedRows プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As DataGridView Dim value As DataGridViewSelectedRowCollection value = instance.SelectedRows
public: property DataGridViewSelectedRowCollection^ SelectedRows { DataGridViewSelectedRowCollection^ get (); }
ユーザーが選択した行を格納している DataGridViewSelectedRowCollection。

SelectedRows プロパティに選択された行を読み込むために、SelectionMode プロパティを FullRowSelect または RowHeaderSelect に設定する必要があります。
このプロパティには、参照された時点の選択の読み取り専用スナップショットが格納されます。このコレクションのコピーを保持し続けた場合、ユーザーが選択を変更した実際の後続の DataGridView 状態とは異なる可能性があります。したがって、このコレクションのコピーは使用しないでください。

SelectedRows プロパティを UserDeletingRow イベントで使用する方法を、次のコード例に示します。この例では、1 行目が SelectedRows コレクションに格納されている場合、削除がキャンセルされます。
Private Sub UserDeletingRow(ByVal sender As Object, _ ByVal e As DataGridViewRowCancelEventArgs) _ Handles DataGridView1.UserDeletingRow Dim startingBalanceRow As DataGridViewRow = DataGridView1.Rows(0) ' Check if the starting balance row is included in the selected rows If e.Row.Equals(startingBalanceRow) Then ' Do not allow the user to delete the Starting Balance row. MessageBox.Show("Cannot delete Starting Balance row!") End If ' Cancel the deletion if the Starting Balance row is included. e.Cancel = True End Sub
private void DataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { DataGridViewRow startingBalanceRow = DataGridView1.Rows[0]; // Check if the Starting Balance row is included in the selected rows if (DataGridView1.SelectedRows.Contains(startingBalanceRow)) { // Do not allow the user to delete the Starting Balance row. if (e.Row.Equals(startingBalanceRow)) { MessageBox.Show("Cannot delete Starting Balance row!"); } // Cancel the deletion if the Starting Balance row is included. e.Cancel = true; } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
その他の技術情報
DataGridView コントロール (Windows フォーム)
Weblioに収録されているすべての辞書からDataGridView.SelectedRows プロパティを検索する場合は、下記のリンクをクリックしてください。

- DataGridView.SelectedRows プロパティのページへのリンク