cmtavares Posted September 13, 2013 at 02:49 AM Report #524410 Posted September 13, 2013 at 02:49 AM (edited) Boas pessoal, estou com o pequeno problema e resolvi vir até aqui pedir alguma ajuda, a minha questão é a seguinte: Neste momento tenho uma checkbox preenchida com valores provenientes de uma base de dados de clientes em SQL-SERVER. O que eu gostaria de fazer era ao colocar o visto fazer com que apareça o nome do cliente ou então o email do mesmo para que depois possa ser enviado por lista de espera. tenho aqui algum código mas isto não está a trabalhar corretamente, Private Sub CheckedListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CheckedListBox1.SelectedIndexChanged Dim i As Integer Dim ponto As String = ";" If CheckedListBox1.CheckedItems.Count - 1 Then txtPara.Text = CheckedListBox1.SelectedItem End If For i = 0 To CheckedListBox1.CheckedItems.Count - 1 txtPara.Text = txtPara.Text + vbNewLine + ponto + CheckedListBox1.SelectedItem Next End Sub se me conseguirem ajudar agradeço, continuação 😉 Edited September 13, 2013 at 01:23 PM by thoga31 GeSHi
nelsonr Posted September 13, 2013 at 08:29 AM Report #524412 Posted September 13, 2013 at 08:29 AM Boas, isso é VBA? Mais parece VB.NET. Em relação à tua questão, usa antes o evento "SelectedValueChanged". Podes fazer assim (não testei): Private Sub CheckedListBox1_SelectedValueChanged(sender As Object, e As EventArgs) Handles CheckedListBox1.SelectedValueChanged Dim ponto As String = ";" txtPara.Text = "" For Each checkbox As String in CheckedListBox1.CheckedItems txtPara.Text = txtPara.Text + vbNewLine + ponto + checkbox Next End Sub
thoga31 Posted September 13, 2013 at 01:26 PM Report #524455 Posted September 13, 2013 at 01:26 PM If CheckedListBox1.CheckedItems.Count - 1 Then O VB.NET faz conversão implícita por defeito, pelo que não te vai avisar que aqui não tens uma condição mas sim um número. Apesar de podermos pensar no type casting e pensar que vai dar bem, nunca é de mais dar a condição directamente. Knowledge is free!
nelsonr Posted September 13, 2013 at 01:45 PM Report #524463 Posted September 13, 2013 at 01:45 PM Tinha respondido no outro topico https://www.portugal-a-programar.pt/topic/62430-checkbox-para-textbox/
thoga31 Posted September 13, 2013 at 01:54 PM Report #524466 Posted September 13, 2013 at 01:54 PM Tinha respondido no outro topico https://www.portugal-a-programar.pt/topic/62430-checkbox-para-textbox/ Situação resolvida. Resposta movida para este tópico. 😉 Knowledge is free!
cmtavares Posted September 16, 2013 at 11:52 PM Author Report #524823 Posted September 16, 2013 at 11:52 PM Boas, isso é VBA? Mais parece VB.NET. Em relação à tua questão, usa antes o evento "SelectedValueChanged". Podes fazer assim (não testei): Private Sub CheckedListBox1_SelectedValueChanged(sender As Object, e As EventArgs) Handles CheckedListBox1.SelectedValueChanged Dim ponto As String = ";" txtPara.Text = "" For Each checkbox As String in CheckedListBox1.CheckedItems txtPara.Text = txtPara.Text + vbNewLine + ponto + checkbox Next End Sub Boas, o seu código ajudou bastante, mas esta aqui uma pequena coisa que não consigo retirar é que quando da check no primeiro cliente o programa adiciona um ponto e virgula quando não devia colocar. Atenciosamente, Carlos Tavares
nelsonr Posted September 17, 2013 at 08:26 AM Report #524831 Posted September 17, 2013 at 08:26 AM Como queres que fique? nome1; nome2; nome3 ? Caso seja, experimenta assim: Private Sub CheckedListBox1_SelectedValueChanged(sender As Object, e As EventArgs) Handles CheckedListBox1.SelectedValueChanged Dim ponto As String = ";" txtPara.Text = "" For Each checkbox As String in CheckedListBox1.CheckedItems If Not String.IsNullOrEmpty(txtPara.Text) Then txtPara.Text = txtPara.Text + ponto + vbNewLine Endif txtPara.Text = txtPara.Text + checkbox Next End Sub
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now