0
votes

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

1
Where do you call SetColumnsReadOnly, is it a TextBox column?Tim Schmelter
Not much to see from the code provided. Can you verify your program actually steps into the method? Can you check all the references of the DataGridView to see if there's some manipulation being made anywhere else?rdoubleui
yes all verified, there is no more code than this so i can not show more, the program does steps into the code which you could also have know because as i stated the code does works for all other columnsGuidoG

1 Answers

0
votes

I was able to fix my problem by moving this column one up in the list. It remains a big mistery why this column behaved like this and I fear that the problem may someday return. Also there is no logic reason why moving the column one up fixed the problem, except for the index nothing at all changed for this column.