Question

est-il possible d'afficher un DataRow à partir d'un DataTable contenant le DataRowState.Deleted?

Scénario: L'utilisateur peut modifier certaines informations de recherche présentées dans la grille. Il peut maintenant supprimer, modifier ou insérer plusieurs entrées et enfin stocker toutes ses informations. change en un clic dans la base de données (en supposant qu'il n'y ait pas de violation de clé primaire ou un autre problème).

Maintenant, je veux coloriser les différentes lignes en fonction de leur statut de montage, mais le les lignes supprimées disparaissent immédiatement.

Avez-vous une idée ou une autre approche pour résoudre ce problème?

Était-ce utile?

La solution

Modifier: j'ai compris que la grille que vous utilisez n'est pas DataGridView . Pour ceux qui veulent faire la même chose avec DataGridView , ils peuvent procéder comme suit:

  1. Créer un DataView :

    DataView myDataView = 
          new DataView(myDataTable, 
                       String.Empty,       // add a filter if you need one
                       "SortByColumn",
                       DataViewRowState.OriginalRows | DataViewRowState.Deleted); 
    
    myDataGridView.DataSource = myDataView;
    
  2. Gestion de UserAddedRow , UserDeletedRow et CellValueChanged :

    private void myDataGridView_UserAddedRow
                (object sender, DataGridViewRowEventArgs e)
    {
        e.Row.DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#CCFF99");
    }
    
    private void myDataGridView_UserDeletedRow
                (object sender, DataGridViewRowEventArgs e)
    {
        e.Row.DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#FFCC99");
    }
    
    private void myDataGridView_CellValueChanged
                (object sender, DataGridViewCellEventArgs e)
    {
       myDataGridView[e.ColumnIndex, e.RowIndex].DefaultCellStyle.BackColor 
                                              = ColorTranslator.FromHtml("#FFFF99");
    }
    
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top