Question DataGridView1 not work CellDoubleClick

ts.analista

Member
Joined
Oct 5, 2012
Messages
7
Location
L. Eduardo - BA
Programming Experience
1-3
Talk guys, good morning.
I'm not getting personal list data from a survey of DataGrid for my Registration form. Remembering that I'm doing a CRUD in my application. See codes

VB.NET:
//CODE Class DALCustomers
 '       
        ''' <summary>
        ''' Obtained by searching the registry ID
        ''' </summary>
        ''' <param name="CustomerID"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
 Public Function GetCustomers(ByVal CustomerID As Integer) As DataRow


            _dlinha = Nothing


            Try


                _sqlcon = New SqlClient.SqlConnection(_conStr)
                _sqlcon.Open()




                _sqlcom = New SqlClient.SqlCommand()
                With _sqlcom
                    .Connection = _sqlcon
                    .CommandType = CommandType.Text


                    .CommandText = "SELECT CustomerID, CustomerNome, CustomerAddress, CustomerPhone, CustomerEmail FROM Customers "


                    .Parameters.Add("@CustomerID", SqlDbType.Int).Value = PessoaID
                End With


                _sqldap = New SqlClient.SqlDataAdapter(_sqlcom)
                _dset = New DataSet()
                _sqldap.Fill(_dset)


                If _dset.Tables(0).Rows.Count > 0 Then
                    _dline = _dset.Tables(0).Rows(0)
                Else
                    _dline = Nothing
                End If


                _sqlcom.Parameters.Clear()
            Catch ex As Exception
                _dline = Nothing
                Throw ex
            Finally
                releasesobjects()
            End Try


            Return _dline


        End Function

//Code Class BLL Customers
Public Function GetCustomers(ByVal CustomersID As String) As DataRow


            _dline = Nothing
            Try
                _obj = New DALCustomers()
                _dlinha = _obj.GetCustomers(CustomersID)
            Catch ex As Exception
                Throw ex
            Finally
                _obj = Nothing
            End Try


            Return _dline


        End Function

Event Code of DataGridView CellDoubleClick



VB.NET:
Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick


        Dim CustomersID As Integer = 0


        Try
            
            _objs = New BLLCustomers()
            _dline = _objs.GetCustomer(DataGridView1.Rows(e.RowIndex).Cells(0).Value)


            Dim frm As New FromCustomers()
            frm.ShowDialog()




            FrmCustomers.txtCustomerID.Text = _dline("CustomerID").ToString()
            FrmCustomers.CustomerNome.Text = _dline("CustomerNome").ToString()
            FrmCustomers.CustomerAddress.Text = _dline("CustomerAddress").ToString()
            FrmCustomers.CustomerPhone.Text = _dline("CustomerPhone").ToString()




        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            _dline = Nothing
            _objs = Nothing
        End Try


    End Sub

Tela de Cadastro 2.png
 
As you can't seem to decide whether you want this information on frm, FromCustomers (I'm assuming that's a simple typo?), or FrmCustomers, I can't say I'm particularly surprised.
 
Dim CustomersID As Integer = 0 Try _objs = New BLLCustomers() _dline = _objs.GetCustomer(DataGridView1.Rows(e.RowIndex).Cells(0).Value) Dim frm As New FrmCustomers() frm.ShowDialog() FrmCustomers.txtCustomerID.Text = _dline("CustomerID").ToString() FrmCustomers.CustomerNome.Text = _dline("CustomerNome").ToString() FrmCustomers.CustomerAddress.Text = _dline("CustomerAddress").ToString() FrmCustomers.CustomerPhone.Text = _dline("CustomerPhone").ToString()
 
No, it wouldn't. The same problem applies. You create the form as frm but assign the values to the textboxes on FrmCustomers. So the visible form 'frm' never gets filled.
 
VB.NET:
//CODE Class DALCustomers
 '       
        ''' <summary>
        ''' Obtained by searching the registry ID
        ''' </summary>
        ''' <param name="CustomerID"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
 Public Function GetCustomers(ByVal CustomerID As Integer) As DataRow




            _dlinha = Nothing




            Try




                _sqlcon = New SqlClient.SqlConnection(_conStr)
                _sqlcon.Open()








                _sqlcom = New SqlClient.SqlCommand()
                With _sqlcom
                    .Connection = _sqlcon
                    .CommandType = CommandType.Text




                    .CommandText = "SELECT CustomerID, CustomerNome, CustomerAddress, CustomerPhone, CustomerEmail FROM Customers "




                    .Parameters.Add("@CustomerID", SqlDbType.Int).Value = PessoaID
                End With




                _sqldap = New SqlClient.SqlDataAdapter(_sqlcom)
                _dset = New DataSet()
                _sqldap.Fill(_dset)




                If _dset.Tables(0).Rows.Count > 0 Then
                    _dline = _dset.Tables(0).Rows(0)
                Else
                    _dline = Nothing
                End If




                _sqlcom.Parameters.Clear()
            Catch ex As Exception
                _dline = Nothing
                Throw ex
            Finally
                releasesobjects()
            End Try




            Return _dline




        End Function


//Code Class BLL Customers
Public Function GetCustomers(ByVal CustomersID As String) As DataRow




            _dline = Nothing
            Try
                _obj = New DALCustomers()
                _dlinha = _obj.GetCustomers(CustomersID)
            Catch ex As Exception
                Throw ex
            Finally
                _obj = Nothing
            End Try




            Return _dline




        End Function


[COLOR=#333333][FONT=Verdana]//Event Code of DataGridView CellDoubleClick[/FONT][/COLOR]


//Code Class BLL Customers
Public Function GetCustomers(ByVal CustomersID As String) As DataRow




            _dline = Nothing
            Try
                _obj = New DALCustomers()
                _dlinha = _obj.GetCustomers(CustomersID)
            Catch ex As Exception
                Throw ex
            Finally
                _obj = Nothing
            End Try




            Return _dline




        End Function
        
        
        Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick




        Dim CustomersID As Integer = 0




        Try
            
            _objs = New BLLCustomers()
            _dline = _objs.GetCustomer(DataGridView1.Rows(e.RowIndex).Cells(0).Value)




            Dim frm As New FromCustomers()
            frm.ShowDialog()








            FrmCustomers.txtCustomerID.Text = _dline("CustomerID").ToString()
            FrmCustomers.CustomerNome.Text = _dline("CustomerNome").ToString()
            FrmCustomers.CustomerAddress.Text = _dline("CustomerAddress").ToString()
            FrmCustomers.CustomerPhone.Text = _dline("CustomerPhone").ToString()








        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            _dline = Nothing
            _objs = Nothing
        End Try




    End Sub


have any tips on how I can I list the data in the form, using these class, what would be the correct way?
I appreciate any help. alas
 
Last edited:
Back
Top