mercredi 1 juillet 2015

Cell click cancel in DataGridView checkbox

I have a checkbox inside a datagridview that allow user to calculate the total amt of the selected row. But I have to make authorization validation that ANY user can tick the rows BUT only MASTER can untick the rows.

So I make the calculation on CellClick event. Here the problem I face is when i click on the combobox, it still will untick no matter how i force it to tick back.

            if (e.ColumnIndex == gv.Columns["ColumnMark"].Index)
            {
                if (gv.Rows[e.RowIndex].Cells["ColumnMark"].Value.ToString() == "1")
                {
                    if (authorized == "TRUE")
                    {
                        gv.Rows[e.RowIndex].Cells["ColumnMark"].Value = 0;
                        DisplayItemTotalAmount();

                    }
                    else
                    {
                        gv.Rows[e.RowIndex].Cells["ColumnMark"].Value = 1;
                        DisplayItemTotalAmount();
                    }

                }
                else
                {
                    gv.Rows[e.RowIndex].Cells["ColumnMark"].Value = 1;
                    DisplayItemTotalAmount();
                }

            }

I had already try on CellBegin event and CellValueChanged event but i will not validated or calculate when i click on the same checkbox second times.

I think there should be have one Event Handler for this. Because the CellClick work but the mark is still perform untick.

Hope anyone can help me and sorry for my bad english.




Aucun commentaire:

Enregistrer un commentaire