Deactivate event cellendedit datagridview

0

I have a DataGridView that gets me values from a SQL Server table, I select a product and when I give click to the next cell, I get its price, this is generated with the event CellEndEdit , but I require change the price value manually.

How do I deactivate that event so I can enter the new price, can it?

What do I want to do with a CheckBoxColumn when I am selected to let me edit and when not, can not be per row or how could it work?

    
asked by Javier Hernandez 19.04.2018 в 20:27
source

1 answer

1

Suppose the following:

In your DataGridView the first column is type CheckBoxColumn whereby it will be the index = 0; and column 3 is the Precio in the event CellValueChanged of your DataGridView can do something like this:

private void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    if (e.ColumnIndex == 1)
    {
        object value = DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
        if (value == true) 
        {
            DataGridView1.Rows[e.RowIndex].Cells[3].ReadOnly = true;
        } else 
        {
            DataGridView1.Rows[e.RowIndex].Cells[3].ReadOnly = false;
        }
    }
}

If this gives you an exception:

object value = DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
if (value == true)

You can also do it like this:

if (Convert.ToBoolean(DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) == true)
  

With this no you are disabling the event CellEndEdit as such, what you are doing is the cell Precio that you want to modify whether or not it is editable.

    
answered by 19.04.2018 / 20:43
source