DataGridView.AreAllCellsSelected(Boolean) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne une valeur indiquant si toutes les DataGridView cellules sont actuellement sélectionnées.
public:
bool AreAllCellsSelected(bool includeInvisibleCells);
public bool AreAllCellsSelected(bool includeInvisibleCells);
member this.AreAllCellsSelected : bool -> bool
Public Function AreAllCellsSelected (includeInvisibleCells As Boolean) As Boolean
Paramètres
- includeInvisibleCells
- Boolean
true pour inclure les lignes et colonnes avec Visible des valeurs de propriété de false; sinon, false.
Retours
true si toutes les cellules (ou toutes les cellules visibles) sont sélectionnées ou s’il n’y a pas de cellules (ou aucune cellule visible) ; sinon, false.
Exemples
L’exemple de code suivant montre comment utiliser cette méthode pour éviter les calculs impliquant la SelectedCells collection.
private void selectedCellsButton_Click(object sender, System.EventArgs e)
{
Int32 selectedCellCount =
dataGridView1.GetCellCount(DataGridViewElementStates.Selected);
if (selectedCellCount > 0)
{
if (dataGridView1.AreAllCellsSelected(true))
{
MessageBox.Show("All cells are selected", "Selected Cells");
}
else
{
System.Text.StringBuilder sb =
new System.Text.StringBuilder();
for (int i = 0;
i < selectedCellCount; i++)
{
sb.Append("Row: ");
sb.Append(dataGridView1.SelectedCells[i].RowIndex
.ToString());
sb.Append(", Column: ");
sb.Append(dataGridView1.SelectedCells[i].ColumnIndex
.ToString());
sb.Append(Environment.NewLine);
}
sb.Append("Total: " + selectedCellCount.ToString());
MessageBox.Show(sb.ToString(), "Selected Cells");
}
}
}
Private Sub selectedCellsButton_Click( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles selectedCellsButton.Click
Dim selectedCellCount As Integer = _
dataGridView1.GetCellCount(DataGridViewElementStates.Selected)
If selectedCellCount > 0 Then
If dataGridView1.AreAllCellsSelected(True) Then
MessageBox.Show("All cells are selected", "Selected Cells")
Else
Dim sb As New System.Text.StringBuilder()
Dim i As Integer
For i = 0 To selectedCellCount - 1
sb.Append("Row: ")
sb.Append(dataGridView1.SelectedCells(i).RowIndex _
.ToString())
sb.Append(", Column: ")
sb.Append(dataGridView1.SelectedCells(i).ColumnIndex _
.ToString())
sb.Append(Environment.NewLine)
Next i
sb.Append("Total: " + selectedCellCount.ToString())
MessageBox.Show(sb.ToString(), "Selected Cells")
End If
End If
End Sub
Remarques
La SelectedCells collection ne fonctionne pas efficacement avec de grandes sélections. Pour déterminer si toutes les cellules de la DataGridView collection ont été sélectionnées avant d’accéder au contenu de la SelectedCells collection, vérifiez la valeur de retour de la AreAllCellsSelected méthode. Toutefois, cette méthode peut entraîner la non-partage des lignes. Pour plus d’informations sur les performances DataGridView, consultez Pratiques de mise à l’échelle du contrôle DataGridView Windows Forms.