locked
Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function. VB.NET RRS feed

  • Question

  • Sub Data_Perusahaan()
            Proses.CloseConn()
    
            Try
                Proses.OpenConn()
                SQL = "SELECT tawar01.kode_pelanggan AS 'KODE PERUSAHAAN', " _
                    & "pelanggan.nama AS 'NAMA PERUSAHAAN', tawar01.att AS 'PENERIMA', tawar01.kode AS 'PENAWARAN', tawar01.alamat as 'ALAMAT', tawar01.tgl AS 'TGL' " _
                    & "FROM tawar01 INNER JOIN pelanggan " _
                    & "ON tawar01.kode_pelanggan = pelanggan.kode " _
                    & "WHERE pelanggan.nama LIKE '%" & Rep(txtCariPerusahaan.Text) & "%' ORDER BY tawar01.tgl DESC"
                perusahaan = Proses.ExecuteQuery(SQL)
                Try
                    Me.DGPerusahaan.DataSource = perusahaan
                    'Me.DGPerusahaan.Columns(0).Visible = False
                    Me.DGPerusahaan.Columns(0).Width = 100 'The Error is Here When I call this form from another form
                    Me.DGPerusahaan.Columns(1).Width = 380
                    Me.DGPerusahaan.Columns(2).Width = 180
                    Me.DGPerusahaan.Columns(3).Width = 190
                    Me.DGPerusahaan.Columns(4).Visible = False
                    Me.DGPerusahaan.Columns(5).Visible = False ' Untuk Memasukan Alamat ke Form utama
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
                
    
                '850
    
                DGPerusahaan.GridColor = Color.White
                DGPerusahaan.DefaultCellStyle.ForeColor = Color.White
                DGPerusahaan.AlternatingRowsDefaultCellStyle.BackColor = Color.Purple
                DGPerusahaan.RowsDefaultCellStyle.BackColor = Color.DarkGreen
                Proses.CloseConn()
    
    
                DGPerusahaan.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                'DGPerusahaan.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
    
                Proses.OpenConn()
    
                Dim myadapter As New MySqlDataAdapter
                Dim sqlquery = "SELECT tawar01.kode_pelanggan AS 'KODE', " _
                    & "pelanggan.nama AS 'NAMA PERUSAHAAN', tawar01.att AS 'PENERIMA', tawar01.kode AS 'PENAWARAN', tawar01.alamat as 'ALAMAT', tawar01.tgl AS 'TGL' " _
                    & "FROM tawar01 INNER JOIN pelanggan " _
                    & "ON tawar01.kode_pelanggan = pelanggan.kode " _
                    & "WHERE pelanggan.nama LIKE '%" & Rep(txtCariPerusahaan.Text) & "%' ORDER BY tawar01.tgl DESC"
    
                Dim mycommand As New MySqlCommand
                mycommand.Connection = Proses.Cn
                mycommand.CommandText = sqlquery
                myadapter.SelectCommand = mycommand
                Dim totalbarang As Integer
                Dim mydata As MySqlDataReader
                mydata = mycommand.ExecuteReader()
    
                totalbarang = 0
                If (mydata.HasRows) Then
                    While (mydata.Read)
                        totalbarang = totalbarang + 1
                    End While
                End If
                lbl_totalperusahaan.Text = Val(totalbarang)
                Proses.CloseConn()
    
            Catch ex As Exception
                MessageBox.Show("Error. Hubungi IT atau periksa ulang data yang di input" + ex.Message, "Hubungi IT", MessageBoxButtons.OK)
            End Try
        End Sub

    Wednesday, November 8, 2017 12:44 AM

All replies

  • Hi Gede,

    >>Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.

    The exception is raised by the DataGridView in order to prevent an infinite loop from occurring. The cause of this is usually one of the following:

    1, Changing the active cell while an operation is being performed on the currently-active cell

    2, Beginning, ending or cancelling edit mode while a cell edit is already in-progress

    3, Any other operation that results in the active cell being changed while the DataGridView is still using it

    Have a look at your handler for the CellValueChanged event and make sure you are not doing any of the above within the handler.

    Refer: Why is my bound DataGridView throwing an “Operation not valid because it results in a reentrant call to the SetCurrentCellAddressCore function” error?

    I'm not sure how do you call this method and where do you call it, maybe try to change the calling method with begin invoke:

    dataGridView1.BeginInvoke(New MethodInvoker(Data_Perusahaan))

    Also please refer to the following similar link:

    Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.

    Error in DatagridView CellEndEdit event.

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Bob Ding Friday, November 10, 2017 9:55 AM
    Wednesday, November 8, 2017 5:39 AM
  • Hi,

    So have you solved this problem now?

    I think the above reply can provide you with a solution, have you tried it?

    If so, hope you can close this thread by marking the reply as answer as this will help others looking for the same or similar issues down the road.

    Best Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 14, 2017 8:29 AM