VB.NET 2015 - Trabalhando os Recursos Simples do componente ListBox (Vídeo)
Autor: Melqui Serrano Arimuya | Publicado: 2015-12-28T20:41:00-04:00






Vamos a trabalhar este artigo referente ao componente ListBox, mais uma vez existem muitas forma de aplicar o listbox, como por exemplo no artigo&nbsp;

VB.NET 2008 - Controlar BackgroundWorker1 e gerando pelo Evento Click e adicionando o resultado na ListBox&nbsp;podemos ver que se aplica de muitas formas, mostra também uma serie de elementos dos que o usuário pode selecionar um ou mais itens


Veja este exemplo&nbsp;VB.NET 2010 - Desenvolvendo Um Registro de Chamadas com ListBox, Button, Textbox e Label simples&nbsp;e&nbsp;VB.NET 2010 - Lista de Paises e Capitais Mediante com objeto TreeVierw e ListaBox


Algumas funções que são usadas com frequências.





Veja o Código Fonte


 

  
Public Class frmListboxSimples

&nbsp;&nbsp;&nbsp; Private Sub btnAdicionar_Click(sender As Object, e As EventArgs) Handles
  btnAdicionar.Click

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If txtAdicionar.Text = "" Then

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  MsgBox("Favor informar um
  valor na caixa de Adicionar um registro. !", MsgBoxStyle.Information, "Arimuya
  - Projeto T.I.")

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Me.LstHistorico.Items.Add(txtAdicionar.Text)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  MsgBox("Valor foi incluido
  na lista de Registro. !", MsgBoxStyle.Information,
  "Arimuya - Projeto T.I.")

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtAdicionar.Text
  = ""

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If

&nbsp;&nbsp;&nbsp; End Sub



&nbsp;&nbsp;&nbsp; Private Sub btnLimpar_Click(sender As Object, e As EventArgs) Handles
  btnLimpar.Click

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LstHistorico.Items.Clear()

&nbsp;&nbsp;&nbsp; End Sub



&nbsp;&nbsp;&nbsp; Private Sub btnDeletarRegistro_Click(sender As Object, e As EventArgs) Handles
  btnDeletarRegistro.Click

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If LstHistorico.SelectedIndex &gt;
  -1 Then

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  LstHistorico.Items.RemoveAt(LstHistorico.SelectedIndex)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If

&nbsp;&nbsp;&nbsp; End Sub



&nbsp;&nbsp;&nbsp; Private Sub btnBloqueadoDesbloqueado_Click(sender As Object, e As EventArgs) Handles
  btnBloqueadoDesbloqueado.Click

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If LstHistorico.Enabled = True Then

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LstHistorico.Enabled = False

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LstHistorico.Enabled = True

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If

&nbsp;&nbsp;&nbsp; End Sub



&nbsp;&nbsp;&nbsp; Private Sub btnOcultarMostrar_Click(sender As Object, e As EventArgs) Handles
  btnOcultarMostrar.Click

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If LstHistorico.Visible = True Then

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LstHistorico.Visible = False

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LstHistorico.Visible = True

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If

&nbsp;&nbsp;&nbsp; End Sub



&nbsp;&nbsp;&nbsp; Private Sub LstHistorico_SelectedIndexChanged(sender As Object, e As EventArgs) Handles
  LstHistorico.SelectedIndexChanged

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If LstHistorico.SelectedIndex &lt;&gt; -1 Then

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  lblSelecionar.Text = ("Foi
  selecionado o valor:" &amp;
  LstHistorico.Text)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If

&nbsp;&nbsp;&nbsp; End Sub





&nbsp;&nbsp;&nbsp; Private Sub
  btnCarregarDados_Click(sender As Object, e As EventArgs) Handles btnCarregarDados.Click

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  LstHistorico.Items.Add("Teclado")

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  LstHistorico.Items.Add("Monitor")

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  LstHistorico.Items.Add("CPU")

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  LstHistorico.Items.Add("Gabinete")

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LstHistorico.Items.Add("Mouse")

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LstHistorico.Items.Add("Pen
  drivers")

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LstHistorico.Items.Add("CDs")

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LstHistorico.Items.Add("Microfone")

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LstHistorico.Items.Add("Parlantes")



&nbsp;&nbsp;&nbsp; End Sub

End Class

 




Baixar o executável de ListBox Simples 2015