Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

BUG: Selected DataGridViewCheckBoxColumn Cell starts BeginEdit immediately after DataGridView.ReadOnly Changed to False, Before the Column or Cell ReadOnly can be set to true

$
0
0

   

This is a BUG because the behavior is unexpected and behaves inconsistently compared to the other column types.  

Related BUG:  The CellBeginEdit event raised when the selected checkbox cell goes into edit mode occurs before the DataGridView's ReadOnlyChanged event.  The reason this is a BUG is because the DataGridView's ReadOnlyChanged event should occur Before the child controls respond to the changed ReadOnly state.

The expected behavior is that the User or Program Code should initiate Editing of a DataGridView Cell and Edit Mode for the Cell should Not be initiated by changing the parent DataGridView's ReadOnly property value.  

For example:  If a DataGridViewTextBoxColumn cell is selected, when changing the DataGridView.ReadOnly from true to false, the cell does Not go into Edit Mode.  However, if the cell is a DataGridViewCheckBoxColumn, the ReadOnly state change causes the checkbox cell to go into Edit Mode and immediately raises the DataGridView_CellBeginEdit event.  Fortunately this bug does Not change the checkbox cell's value!

Here is a typical problem caused by this BUG is that the CheckBox cell 

private void Set_MyCheckboxColumn_toReadOnly()
{
  int myCheckboxColIndex = 0;
  this.myDGV.ReadOnly = true;

  // Note:  Changing the DataGridView.ReadOnly to false changes all the Column.ReadOnly values to false.
  this.myDGV.ReadOnly = false;
  // BUG:  If a checkbox cell was selected, it is will go into Edit Mode before we can set it to ReadOnly!
  //       The CellBeginEdit event will happen now.
  //       If other column type cells are selected, they will not go into Edit Mode now.
  //       The CellBeginEdit event does not happen when other column type cells are selected.

  // Only set the Checkbox Column to ReadOnly, allow other Text Columns to be editable.
  // BUG Result:  The selected Checkbox cell is already in Edit Mode before now!
  this.myDGV.Columns[myCheckBoxColIndex].ReadOnly = true;
}

private void myDGV_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
  // BUG Result:  The selected checkbox cell is now in Edit Mode before we can set it to ReadOnly.
}

private void myDGV_ReadOnlyChanged(object sender, EventArgs e)
{
  // Related BUG Result:  Too Late!  Selected Checkbox Cell already knows the ReadOnly has change and has already changed Edit Mode.
}


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>