Learn how to a build a cloud-first strategyRegister Now


Checkboxes in first row of DataGridView are readonly

Posted on 2007-10-03
Medium Priority
Last Modified: 2013-11-07
I have a datagridview in my app which is bound to a datatable, the datagridview has predefined columns, both text and checkboxes.

For some reason the top row will not allow me to change the state of the checkboxes by clicking on them. I can edit the text in the row - so it is not a problem of the row being readonly. Also, if I sort the data by clicking a header then whichever row ends up at the top will not accept changes to the checkboxes and the previously uneditable row (which is now further down the list) now does accept changes to the checkboxes.

It seems to me that there is a problem with the DataGridView control in the framework, so my question is: has anyone else come across this and did they find a workaround?
Question by:Solar_Flare
  • 3
  • 2
LVL 15

Expert Comment

ID: 20011070
Try putting this on form load event.

Datagridview.column(0).readonly = true
LVL 15

Expert Comment

ID: 20011081
LVL 39

Accepted Solution

appari earned 2000 total points
ID: 20011082
never faced this kind of problem. it has something to do with the code only.
if you try to do a simillar thing on a new form is it behaving in the same way?
can you post your existing code, specially from the places where you are creating the columns and binding the data.
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

LVL 15

Expert Comment

ID: 20011096
I think you had a similar problem with this guy, do check it out.

LVL 15

Author Comment

ID: 20011366
OK I have managed to figure out what was causing it, heres an explanation:

I want the checkbox columns to be as small as possible for displaying item statuses, so I set the DGV to autosize columns = Fill. Then on form load I loop through all the columns and assign images to the header cells as they are smaller than text. I also set the column sizing in the loop:
For Each c As DataGridViewColumn In dg1.Columns
            If c.DataPropertyName.StartsWith("Status") Then
                    Dim hc As New DataGridViewImageColumnHeaderCell
                    hc.Image = ImageList1.Images(c.Index)
                    c.HeaderCell = hc
                Catch ex As Exception
                End Try

                c.MinimumWidth = 18
                c.FillWeight = 1
                c.HeaderText = ""
      end if

Not that I set the FillWieght to 1 in order to minimize the space that the columns occupies - instead I rely on the minimum width attribute to ensure the checkbox is visible.

if I change the FillWeight to something larger, say 20, then it all works correctly! I can only presume that there is some very obscure bug in the datagridview in situations where the fillweight is tiny (perhaps less than 0.5% so gets rounded to 0?)which affects the click handling for checkbox columns in the top row.

I tried replicating the problem in a new project but the original DGV with the problem is quite complex and I don't have time to copy it exactly. A quick attempt did not yield the same behaviour so this is obviously pretty obscure.
LVL 15

Author Comment

ID: 20018324
appari, you were correct that it had to do with my code. I will accept an answer so that someone else with this problem can find it.

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question