locked
datagridview column header checkbox RRS feed

Answers

  • Hi bahushekh,

    Thanks for your post!

    Please kindly check the following sample code for reference.

    Public Class DGVcolumnheader
      Inherits Form
      Public Sub New()
        InitializeComponent()
      End Sub
      Private col As DataGridViewCheckBoxColumn
      Private chkBox As CheckBox
      Private Sub DGVcolumnheader_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        col = New DataGridViewCheckBoxColumn()
        col.Name = "Checkbox"
        col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        Me.DataGridView1.Columns.Add(col)   
        chkBox = New CheckBox()
        Dim rect As Rectangle = Me.DataGridView1.GetCellDisplayRectangle(0, -1, True)
        chkBox.Size = New Size(18, 18)
        chkBox.Location = rect.Location
        AddHandler chkBox.CheckedChanged, AddressOf chkBox_CheckedChanged
        Me.DataGridView1.Controls.Add(chkBox)
      End Sub
      Private Sub chkBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        For i As Integer = 0 To Me.DataGridView1.RowCount - 1
          Me.DataGridView1(0, i).Value = Me.chkBox.Checked
        Next
        Me.DataGridView1.EndEdit()
      End Sub
    End Class
    
    Best Regards,
    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by bahushekh Wednesday, December 29, 2010 6:15 AM
    Wednesday, December 29, 2010 4:14 AM

All replies

  • You cannot use checkboxes in the column headers of your datagridview only text it is not a kind of checked list box which is turned around.

    In row/column cells you can use checkboxes in a same way as a checked listbox. 


    Success
    Cor
    Monday, December 27, 2010 12:32 PM
  • Hi bahushekh,

    Thanks for your post!

    Please kindly check the following sample code for reference.

    Public Class DGVcolumnheader
      Inherits Form
      Public Sub New()
        InitializeComponent()
      End Sub
      Private col As DataGridViewCheckBoxColumn
      Private chkBox As CheckBox
      Private Sub DGVcolumnheader_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        col = New DataGridViewCheckBoxColumn()
        col.Name = "Checkbox"
        col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        Me.DataGridView1.Columns.Add(col)   
        chkBox = New CheckBox()
        Dim rect As Rectangle = Me.DataGridView1.GetCellDisplayRectangle(0, -1, True)
        chkBox.Size = New Size(18, 18)
        chkBox.Location = rect.Location
        AddHandler chkBox.CheckedChanged, AddressOf chkBox_CheckedChanged
        Me.DataGridView1.Controls.Add(chkBox)
      End Sub
      Private Sub chkBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        For i As Integer = 0 To Me.DataGridView1.RowCount - 1
          Me.DataGridView1(0, i).Value = Me.chkBox.Checked
        Next
        Me.DataGridView1.EndEdit()
      End Sub
    End Class
    
    Best Regards,
    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by bahushekh Wednesday, December 29, 2010 6:15 AM
    Wednesday, December 29, 2010 4:14 AM
  • thanks sir ..
    Wednesday, December 29, 2010 6:15 AM