Checkboxes in first row of DataGridView are readonly

Posted on 2007-10-03
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
    LVL 15

    Expert Comment

    Try putting this on form load event.

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

    Expert Comment

    LVL 39

    Accepted Solution

    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.
    LVL 15

    Expert Comment

    I think you had a similar problem with this guy, do check it out.
    LVL 15

    Author Comment

    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

    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

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now