Jump to content

Recommended Posts

Posted

Boas pessoal tou aqui com alguns erros que gostava de saber se me podiam ajudar.

O primeiro é: eu tenho dois radiobutton e uma textbox, selecciona no radiobutton a pesquisa que quero fazer e os resultados vai aparecer numa listbox que tenho e se fizer uma pesquisa no primeiro radiobutton depois no segundo e depois voltar ao primeiro dame este erro:

http://img12.imageshack.us/img12/7482/91448418.png

Posted

O 1º erro está a dizer-te que não tens nenhum item seleccionado na ListBox

O 2º erro devias criar outro tópico, 1 dúvida / tópico é uma boa regra para te responderem mais depressa

Ricardo Timóteo

Posted

O 1º erro está a dizer-te que não tens nenhum item seleccionado na ListBox

O 2º erro devias criar outro tópico, 1 dúvida / tópico é uma boa regra para te responderem mais depressa

E como resolvo isso?

Ok ja criei

Posted

Agora não tenho o VB.NET, depois posso confirmar, mas qualquer coisa como:

if (listbox.SelectedValue.ToString<>"") then ...

ou

if (listbox.SelectedValue.ToString.Len<>0) then ...

Ricardo Timóteo

Posted

Agora não tenho o VB.NET, depois posso confirmar, mas qualquer coisa como:

if (listbox.SelectedValue.ToString<>"") then ...

ou

if (listbox.SelectedValue.ToString.Len<>0) then ...

Nao da com os dois exemplos da logo esse mesmo erro

Posted

Eu os codigos que tenho para este efeito sao os seguintes:

Botao de Pesquisa:

Private Sub bt_search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_search.Click
        If RadioButtoncontactos.Checked Then
            Form_view.SelectedTab = Tab_contactos ' Seleccionar TAB
            pesquisacontactos()
        ElseIf RadioButtonempresas.Checked Then
            Form_view.SelectedTab = Tab_Empresas
            pesquisaempresas()
        End If

Processo pesquisacontactos

Private Sub pesquisacontactos()
        If TextBoxsearch.Text.Trim.Length > 0 Then
            pesquisaerro.SetError(TextBoxsearch, "")
            Dim da As BDSofioDataSetTableAdapters.ContactosTableAdapter = New BDSofioDataSetTableAdapters.ContactosTableAdapter
            ListBox.DataSource = da.GetDataByNome("%" & TextBoxsearch.Text & "%")
            ListBox.DisplayMember = "Nome"
            ListBox.ValueMember = "ID_Contacto"
            ListBox.Refresh()
        Else
            pesquisaerro.SetError(TextBoxsearch, "Informe o nome do contacto com no mínimo 2 caracteres...")
        End If
    End Sub

Processo pesquisaempresas

Private Sub pesquisaempresas()
        If TextBoxsearch.Text.Trim.Length > 0 Then
            pesquisaerro.SetError(TextBoxsearch, "")
            Dim da As BDSofioDataSetTableAdapters.EmpresasTableAdapter = New BDSofioDataSetTableAdapters.EmpresasTableAdapter
            ListBox.Visible = True
            ListBox.DataSource = da.GetDataByNome_emp("%" & TextBoxsearch.Text & "%")
            ListBox.DisplayMember = "Empresa"
            ListBox.ValueMember = "ID_Empresa"
            ListBox.Refresh()
        Else
            pesquisaerro.SetError(TextBoxsearch, "Informe o nome da empresa com no mínimo 2 caracteres...")
        End If
    End Sub

Depois ao clicar em um resultado para os detalhes aparecerem no formulário

Private Sub ListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox.SelectedIndexChanged
        If RadioButtoncontactos.Checked = True Then
            If (ListBox.SelectedValue.ToString() <> "System.Data.DataRowView") Then
                carregacontactos(CInt(Me.ListBox.SelectedValue))
            End If
        ElseIf RadioButtonempresas.Checked = True Then
            If (ListBox.SelectedValue.ToString() <> "System.Data.DataRowView") Then
                carregaempresas(CInt(Me.ListBox.SelectedValue))
            End If
        End If
    End Sub
[code]

Processo Carregacontactos

[code]
Private Sub carregacontactos(ByVal ID_Contacto As Integer)
        Dim strConn As String = My.Settings.BDSofioConnectionString.ToString()
        Dim strSQL As String = "Select * from Contactos Where ID_Contacto = " & ID_Contacto
        Dim dr As SqlDataReader

        'define objeto connection e command
        Dim con As New SqlConnection(strConn)
        Dim cmd As New SqlCommand(strSQL, con)
        Try
            con.Open()
            dr = cmd.ExecuteReader
            If (dr.HasRows) Then
                dr.Read()
                ID_ContactoTextBox.Text = dr("ID_Contacto").ToString
                ID_EmpresaComboBox.SelectedValue = dr("ID_Empresa").ToString
                NomeTextBox.Text = dr("Nome").ToString
                CargoTextBox.Text = dr("Cargo").ToString
                Telefone_EmpresaTextBox.Text = dr("Telefone_Empresa").ToString
                Telefone_PessoalTextBox.Text = dr("Telefone_Pessoal").ToString
                Tlmvl_EmpresaTextBox.Text = dr("Tlmvl_Empresa").ToString
                Tlmvl_PessoalTextBox.Text = dr("Tlmvl_Pessoal").ToString
                EmailTextBox.Text = dr("Email").ToString
                validcontactmail()
                FaxTextBox.Text = dr("Fax").ToString
                NotasRichTextBox.Text = dr("Notas").ToString
            End If
        Catch ex As Exception
            MsgBox("Erro ao obter dados. Erro : " & ex.Message)
        Finally
            con.Close()
        End Try
    End Sub

Processo Carregaempresas

Private Sub carregaempresas(ByVal ID_Empresa As Integer)
        Dim strConn As String = My.Settings.BDSofioConnectionString.ToString()
        Dim strSQL As String = "Select * from Empresas Where ID_Empresa = " & ID_Empresa
        Dim dr As SqlDataReader

        'define objeto connection e command
        Dim con As New SqlConnection(strConn)
        Dim cmd As New SqlCommand(strSQL, con)
        Try
            con.Open()
            dr = cmd.ExecuteReader
            If (dr.HasRows) Then
                dr.Read()
                empID_EmpresaTextBox.Text = dr("ID_Empresa").ToString
                empEmpresaTextBox.Text = dr("Empresa").ToString
                empID_TEmpresaComboBox.SelectedValue = dr("ID_TEmpresa").ToString
                empTelefoneTextBox.Text = dr("Telefone").ToString
                empFaxTextBox.Text = dr("Fax").ToString
                empEmailTextBox.Text = dr("Email").ToString
                validempmail()
                empEndereçoTextBox.Text = dr("Endereço").ToString
                empLocalidadeTextBox.Text = dr("Localidade").ToString
                empCodigo_PostalTextBox.Text = dr("Codigo_Postal").ToString
                empPaisTextBox.Text = dr("Pais").ToString
                empWebTextBox.Text = dr("Web").ToString
                validempweb()
            End If
        Catch ex As Exception
            MsgBox("Erro ao obter dados. Erro : " & ex.Message)
        Finally
            con.Close()
        End Try
    End Sub

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.