Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey guys!
i have a datagridview (dg) in my winform program. when the user choose a table from the comboBox, the 'LoadContent' function hit and load the records to the dg.
on the RowLeave event of the dg, i want the dg will updated automatically but nothing happens, non even an excepption. heres the code:
VB
Private Sub LoadContent(tbl As String)
    Dim dt As New DataTable
    Using conn As New SqlConnection("Initial Catalog=" & cmbDataBases.Text & ";" & "Data Source=localhost;Integrated Security=SSPI;")
        Dim adpBooks As New SqlDataAdapter("SELECT * FROM " & tbl, conn)
        adpBooks.Fill(dt)
        dg.DataSource = dt
    End Using
End Sub
Private Sub dg_RowLeave(sender As Object, e As DataGridViewCellEventArgs) Handles dg.RowLeave
    Application.DoEvents()
    Dim con As New SqlConnection()
    con.ConnectionString = connectionString
    con.Open()
    Dim [update] As New SqlCommand("SELECT * FROM " & cmbTables.Text, con)
    Dim da As New SqlDataAdapter([update])
    da.SelectCommand = [update]
    Dim dtab As New DataTable()
    Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)
    da.Update(dtab)
    con.Close()
End Sub
Posted
Comments
Ralf Meier 22-Jul-15 6:52am    
I'm not quiet sure what you are trying to achieve.
I think you should better use the Event "CellValueChanged" or "CurrentCellChanged".
It is posible that at time of the RowLeave-Event the inner DataTable is not refreshed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900