CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2006
    Posts
    141

    Automatically checked for dynamic check box in datagrid view

    Hi,
    I have a checkbox that is dynamically added to the datagridview.I would like to have the checked box checked automatically when it is created.I do not want to loop the datagridview to get the checked box checked which work like this:
    Code:
    this.dataGridView1.Rows[RowIndex].Cells[ColumnIndex].Value = true
    I find no ways to do this.Below is my coding:
    Code:
     DataGridView1.Columns.Add(CreateCheckBoxColumn)
    
        Private Function CreateCheckBoxColumn() As DataGridViewCheckBoxColumn
            Dim dataGridViewCheckBoxColumn1 _
                As New DataGridViewCheckBoxColumn()
    
            dataGridViewCheckBoxColumn1.HeaderText = "Insert"
            dataGridViewCheckBoxColumn1.TrueValue = True
            dataGridViewCheckBoxColumn1.FalseValue = False
            dataGridViewCheckBoxColumn1.IndeterminateValue = 3
            dataGridViewCheckBoxColumn1.ThreeState = True
            Return dataGridViewCheckBoxColumn1
            Return dataGridViewCheckBoxColumn1
    
        End Function

    Does anyone has idea on dooing this?

  2. #2
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: Automatically checked for dynamic check box in datagrid view

    Use RowsAdded eveent to set the checkBoxCOlumns value to true
    Code:
        Private Sub DataGridView1_RowsAdded(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles DataGridView1.RowsAdded
            DataGridView1.Rows(e.RowIndex).Cells(DataGridView1.Columns("Insert").Index).Value = True
        End Sub
    Also add this to initialization of checkboxColumn
    Code:
    dataGridViewCheckBoxColumn1.Name = "Insert"

  3. #3
    Join Date
    Jul 2006
    Posts
    141

    Talking Re: Automatically checked for dynamic check box in datagrid view

    Got it,Thanks!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured