Datagridview VB Celulas Editaveis

Asked

Viewed 382 times

7

Hello, I have a Datagridview that is populated by a Bindingsource and when I load the data I can’t edit the Cells with value, only when I load the empty Datagridview, I tried to use DataGridView1.BeginEdit(True) but it doesn’t work!

Code:

 Private Sub CarregarDataGrid()
    Try
        DataGridView1.DataSource = Nothing
        DataGridView1.AutoGenerateColumns = False
    Catch ex As Exception
        MsgBox("Erro ao Limpar o DataSource do DataGridView")
        Exit Sub
    End Try
    strsql = "select * from Usuarios"

    Dim objCommand As New MySqlCommand(strsql, conn)
    Dim dr_temp As MySqlDataReader
    Dim bs_temp As BindingSource = New BindingSource

    Try
        dr_temp = objCommand.ExecuteReader()
        bs_temp.DataSource = dr_temp
        DataGridView1.DataSource = bs_temp
    Catch ex As Exception
        MsgBox("Erro")
        Exit Sub
    End Try

    confiDataGrid()
End Sub

Configure Datagrid:

Private Sub confiDataGrid()
    If btnManutencao.BackColor = Color.Silver Then
        DataGridView1.AutoGenerateColumns = True
        With DataGridView1
            Try
                .Columns(0).HeaderText = "Codigo Usuario"
            Catch ex As Exception
                MsgBox("Erro")
                Exit Sub
            End Try
            .Columns(1).HeaderText = "Observações"
            .Columns(2).HeaderText = "Data Registro"
            .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        End With
    End If
End Sub

I would just like to know how to make it editable by clicking on the cell. Thank you in advance!

1 answer

1

Try to add the line:

DataGridview1.ReadOnly = False

After your DGV is populated. On the basis this will allow it to be edited.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.