Bonjour,

Je souhaite interdit la possibilité de cocher une case à cocher contenue dans chacune des lignes d'une datagrid , si le contenue de la ligne ne respecte pas certains critères.

Je pars sur cet évènement : CellValueChanged

Si la valeur de ma case à cocher change donc si je la coche , et que ma ligne ne satisfait pas à mes critères , je veux la décocher.

Voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
 
        private void dataGridViewImport_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (dataGridViewImport.IsCurrentCellDirty)
            {
                dataGridViewImport.CommitEdit(DataGridViewDataErrorContexts.Commit);
            }
        }
 
.....
 
// If a check box cell is clicked, this event handler disables  
        // or enables the button in the same row as the clicked cell.
        private void dataGridViewImport_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int indexRow = e.RowIndex; //Index de la ligne
 
            if (indexRow != -1)
            {
                //bouton_affectation_indi viduel_creneau
                if (e.ColumnIndex == dataGridViewImport.Columns["SELECTION"].Index)
                {
                    if ((bool)dataGridViewImport.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == true)
                    {
                        //analyse des champs obligatoires
                        List<string> mandatoryProperty = new List<string>();
                        Participant participant = listParticipants[indexRow];
                        mandatoryProperty = mandatory_Analysis(participant);
                        if (mandatoryProperty.Count > 0)
                        {
                                                        dataGridViewImport.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
                            dataGridViewImport.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;
                            dataGridViewImport.Invalidate();
                        }
                    }
                }
            }
        }
Je vois pas ce qui cloche mais le blocage ne se fait pas .....

Quelqu'un a t'il une idée ?