CheckBox Column in DataGridView defaults to ReadOnly being True?

I have a Column in my DGV that is defined as a DataGridViewCheckBoxCell. My query that is bound to the DGV looks like this:

SELECT      0 AS Selected, EquipID, EquipName, Model, SN, Accredited, Description FROM CalEquip ORDER BY TypeID, EquipName

The first column acts as my CheckBox Column in my DGV. My problem is that even when I manually set the ReadOnly property to False, I run the app and when I try to check/uncheck the column, it won't allow me to. When I go back into the designer and look at that Column, it shows the ReadOnly property is True. What am I doing wrong?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
Your value of zero is seen as a calculated field, and calculated fields cannot be updated.

Either create a dummy field in you database, or leave out the Selected field and add the Checkbox column through your code after the grid is created, with something like the following:

Dim selectedColumn As New DataGridViewCheckBoxColumn()
selectedColumn.HeaderText = "X"
selectedColumn.DisplayIndex = 0
selectedColumn.Width = 25

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BlakeMcKennaAuthor Commented:
Thanks James...that worked!
BlakeMcKennaAuthor Commented:
I am allowed to check/uncheck that field now but now the problem is that it always loads as checked. I need to load in an unchecked mode.
Jacques Bourgeois (James Burger)PresidentCommented:
If you did it through an extra field instead of doing it with the extra column added through code, it gets updated along with the other columns.

You can get rid of that 4 different ways:

- Remove the checks through code before doing an update.
- When finished working with the data, run a SQL command that resets the value to False for all rows where it is True in the database.
- Or run the same command before filling up the grid.
- Do not use the field trick, and use my second recommendation instead.
BlakeMcKennaAuthor Commented:
Thanks James, I'll give it a try!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.