2 Replies - 162 Views - Last Post: 02 January 2018 - 07:41 PM Rate Topic: -----

#1 pjfatboy1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 27-February 16

Datagridview column font format

Posted 02 January 2018 - 04:46 PM

Can someone tell me what I am doing wrong with this code. I'm wanting to add a check mark in one of the columns in a datagridview? What I am getting is a "P". Thanks....
With dgvWorkAssignment
    If e.ColumnIndex = 1 Then
        If .Rows(e.RowIndex).Cells(1).Value = Nothing Then
            .Rows(e.RowIndex).Cells(1).Value = "P"
            .Columns(1).DefaultCellStyle.Font = New Font("Wingdings2", 14, FontStyle.Bold)
        Else
            .Rows(e.RowIndex).Cells(e.ColumnIndex).Value = Nothing
        End If
    Else
        MsgBox("Wrong column")
    End If
End With



Is This A Good Question/Topic? 0
  • +

Replies To: Datagridview column font format

#2 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1464
  • View blog
  • Posts: 3,713
  • Joined: 01-February 13

Re: Datagridview column font format

Posted 02 January 2018 - 05:33 PM

How did you add the columns to the DataGridView?

If you added them in the Designer window, in the DataGridView's Columns property, then you need to re-open that Edit Columns dialog in the Designer window, select the column (on the left), and change its ColumnType property to a "DataGridViewCheckBoxColumn" type (on the right).

If you added the columns dynamically in your code, then you need to create a new DataGridViewCheckBoxColumn, set it's Name and Header Text, and whatever other properties you want, and then add that to the DataGridView. For example...
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim cbxColumn As New DataGridViewCheckBoxColumn(False) 'create the new CheckBox type column
        cbxColumn.Name = "ColumnName" 'set it's name
        cbxColumn.HeaderText = "Column Text" 'set it's header text
        DataGridView1.Columns.Add(cbxColumn) 'add it to the DataGridView
    End Sub



As far as i am aware, you can not add text to a CheckBox type column, the column will only contain a CheckBox.
Was This Post Helpful? 0
  • +
  • -

#3 pjfatboy1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 27-February 16

Re: Datagridview column font format

Posted 02 January 2018 - 07:41 PM

I did create the column in the Designer window. I didn't realize that the datagridview has a checkbox column built in. Thanks for the info IronRazer.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1