none
Enable edit column in datagridview at runtime RRS feed

  • Question

  • Hi

    How can I enable edit column feature in datagrid view at runtime
    I need to turn on column editting at runtime, edit a cell content and then turn off column editing
    I am using VB2008

    Thank you
    Engineer
    Tuesday, January 5, 2010 5:39 AM

Answers

  • Here you go

    private void // ERROR: Handles clauses are not supported in C# CheckBox1_CheckedChanged(System.Object sender, System.EventArgs e)
    {
        
        DataGridViewColumn dgvColumn = this.DataGridView1.Columns("ProductName");
        
        if (this.CheckBox1.CheckState == CheckState.Checked) {
            dgvColumn.ReadOnly = true;
        }
        else {
            dgvColumn.ReadOnly = false;
            
            
        }
    }

    John
    Wednesday, January 6, 2010 8:46 PM

All replies

  • Make your column property ReadOnly TRUE/FALSE as per your requirement. This will help for enabling disabling of editing functionlaity in DataGridView
    Thanks Mike --------Please mark as answer if it is useful----------
    Tuesday, January 5, 2010 11:01 AM
  • Hi Batico,
    Here is a simple example that you can use.

        Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    
            Dim dgvColumn As DataGridViewColumn = Me.DataGridView1.Columns("ProductName")
    
            If Me.CheckBox1.CheckState = CheckState.Checked Then
                dgvColumn.ReadOnly = True
            Else
                dgvColumn.ReadOnly = False
            End If
    
    
        End Sub

    John
    Tuesday, January 5, 2010 11:03 AM
  • can amyone give this code in c#?
    URGENT::
    Wednesday, January 6, 2010 4:33 PM
  • Here you go

    private void // ERROR: Handles clauses are not supported in C# CheckBox1_CheckedChanged(System.Object sender, System.EventArgs e)
    {
        
        DataGridViewColumn dgvColumn = this.DataGridView1.Columns("ProductName");
        
        if (this.CheckBox1.CheckState == CheckState.Checked) {
            dgvColumn.ReadOnly = true;
        }
        else {
            dgvColumn.ReadOnly = false;
            
            
        }
    }

    John
    Wednesday, January 6, 2010 8:46 PM