j0hnstew
j0hnstew

Reputation: 709

Vb.Net CheckBox Column Not Displaying

I am trying to simply add a CheckBox Column to my DataGridView but have been unsuccessful in trying to do so.

'setup table
        Dim dt As DataTable = New DataTable()

        sdrReader = cmdShowSection.ExecuteReader()
        dt.Load(sdrReader)


        'set DGV1 source to dts
        DataGridView1.DataSource = dt

        Dim column As New DataGridViewCheckBoxColumn()
        With column
            .HeaderText = "Hello"
            .Name = "Hello"
            .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
            .FlatStyle = FlatStyle.Standard
            .CellTemplate = New DataGridViewCheckBoxCell()
            .CellTemplate.Style.BackColor = Color.Beige
        End With

        DataGridView1.Columns.Insert(0, column)

When I run this the background for the first column is Beige but the CheckBox does not show up. I tried running this same code on a blank form with a blank DGV and it worked fine, no problem. I am not sure what I am doing that it doesn't like right now.

Upvotes: 1

Views: 1163

Answers (1)

j0hnstew
j0hnstew

Reputation: 709

After struggling over this for the better part of the day the problem was that the width was too small for the column to display the checkbox. I set the column width to fit it and walah! It worked! So make sure that the width is truly set to what is supposed to be if you are having a similar problem.

Upvotes: 1

Related Questions