I have a DataGridView (in a winforms application) with several columns and I want to set some columns readonly in code. This works for all columns but one, this one column refuses to become readonly for some reason. The property ReadOnly is set in code, and when I check the property it reads True but the column is still editable. What could cause this behaviour ?
my code so far :
private void SetColumnsReadOnly()
{
bool readOnlyValue = true; // _IsInvoicedPurchase || _IsInvoicedSales;
gttDataGridViewCar.Columns["ID"].ReadOnly = readOnlyValue;
gttDataGridViewCar.Columns["Name"].ReadOnly = readOnlyValue;
gttDataGridViewCar.Columns["Status"].ReadOnly = readOnlyValue;
// this one does not wants to get readonly !!!!
gttDataGridViewCar.Columns["Reason"].ReadOnly = readOnlyValue;
}
After executing this method, all columns will be readonly except column "Reason". The property ReadOnly for this column is True, but it still can be edited.
Does anybody knows any reasons why this could be happening ?
EDIT: the datagridview is bound to a BindingSource, which is bound to a DataTable that is filled in code.
EDIT: Verified that the code is executed
I put a button on the form check the state of the column after executing SetColumnsReadonly() The readonly property of the column is TRUE but it is still editable
SetColumnsReadOnly
, is it aTextBox
column? – Tim SchmelterDataGridView
to see if there's some manipulation being made anywhere else? – rdoubleui