DataGridViewSortCompareEventHandler Delegato
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rappresenta il metodo che gestirà l'evento SortCompare di un controllo DataGridView.
public delegate void DataGridViewSortCompareEventHandler(System::Object ^ sender, DataGridViewSortCompareEventArgs ^ e);
public delegate void DataGridViewSortCompareEventHandler(object sender, DataGridViewSortCompareEventArgs e);
public delegate void DataGridViewSortCompareEventHandler(object? sender, DataGridViewSortCompareEventArgs e);
type DataGridViewSortCompareEventHandler = delegate of obj * DataGridViewSortCompareEventArgs -> unit
Public Delegate Sub DataGridViewSortCompareEventHandler(sender As Object, e As DataGridViewSortCompareEventArgs)
Parametri
- sender
- Object
Origine dell'evento.
Oggetto DataGridViewSortCompareEventArgs che contiene i dati dell'evento.
Esempio
Nell'esempio di codice seguente viene illustrato l'uso di SortCompare in un ordinamento a più colonne. Questo esempio fa parte di un esempio più ampio fornito in Procedura: Personalizzare l'ordinamento nel controllo DataGridView Windows Forms.
private void dataGridView1_SortCompare(object sender,
DataGridViewSortCompareEventArgs e)
{
// Try to sort based on the cells in the current column.
e.SortResult = System.String.Compare(
e.CellValue1.ToString(), e.CellValue2.ToString());
// If the cells are equal, sort based on the ID column.
if (e.SortResult == 0 && e.Column.Name != "ID")
{
e.SortResult = System.String.Compare(
dataGridView1.Rows[e.RowIndex1].Cells["ID"].Value.ToString(),
dataGridView1.Rows[e.RowIndex2].Cells["ID"].Value.ToString());
}
e.Handled = true;
}
Private Sub DataGridView1_SortCompare( _
ByVal sender As Object, ByVal e As DataGridViewSortCompareEventArgs) _
Handles DataGridView1.SortCompare
' Try to sort based on the contents of the cell in the current column.
e.SortResult = System.String.Compare(e.CellValue1.ToString(), _
e.CellValue2.ToString())
' If the cells are equal, sort based on the ID column.
If (e.SortResult = 0) AndAlso Not (e.Column.Name = "ID") Then
e.SortResult = System.String.Compare( _
DataGridView1.Rows(e.RowIndex1).Cells("ID").Value.ToString(), _
DataGridView1.Rows(e.RowIndex2).Cells("ID").Value.ToString())
End If
e.Handled = True
End Sub
Commenti
Quando si crea un delegato DataGridViewSortCompareEventHandler, si identifica il metodo che gestirà l'evento. Per associare l'evento al gestore eventi in uso, aggiungere all'evento un'istanza del delegato. Il gestore eventi viene chiamato ogni volta che si verifica l'evento, a meno che non venga rimosso il delegato. Per altre informazioni sui delegati del gestore eventi, vedere Gestione e generazione di eventi.
Metodi di estensione
GetMethodInfo(Delegate) |
Ottiene un oggetto che rappresenta il metodo rappresentato dal delegato specificato. |