footboyedit Posted February 11, 2016 at 10:35 AM Report #593339 Posted February 11, 2016 at 10:35 AM Como eu posso mostrar uma especie de "descricao" na combobox conforme o valor que para lá é enviado? De preferencia indo buscar essa descricao à base de dados.
vikcch Posted February 14, 2016 at 01:59 PM Report #593488 Posted February 14, 2016 at 01:59 PM (edited) Não sei se é bem isto que queres, mas fica aqui... Este codigo mostra-te uma descrição conforme passas com o rato por cima dos itens da combobox.. Usa uma classe (Pessoa) que tem o valor do item (Nome) e a descrição: Tem uma combobox (ComboBox1) e uma label (Label1) que mostra a descrição Form1: Option Explicit On Option Strict On Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.ComboBox1.DrawMode = DrawMode.OwnerDrawFixed AddHandler ComboBox1.DrawItem, AddressOf ComboBox1_DrawItem Me.ComboBox1.Items.Add(New Pessoa("Maria", "Olhos verdes")) Me.ComboBox1.Items.Add(New Pessoa("Joana", "Cabelo comprido")) Me.ComboBox1.Items.Add(New Pessoa("Rita", "Mamas grandes")) End Sub Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem e.DrawBackground() If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then e.Graphics.DrawString(ComboBox1.Items(e.Index).ToString, e.Font, Brushes.White, e.Bounds) Dim p As Pessoa = DirectCast(Me.ComboBox1.Items(e.Index), Pessoa) Me.Label1.Text = p.Descricao Else e.Graphics.DrawString(ComboBox1.Items(e.Index).ToString, e.Font, Brushes.Black, e.Bounds) End If End Sub Private Sub ComboBox1_DropDownClosed(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.DropDownClosed Me.Label1.Text = String.Empty End Sub End Class Classe Pessoa: Option Explicit On Option Strict On Public Class Pessoa Private _nome As String Private _descricao As String Public ReadOnly Property Descricao() As String Get Return _descricao End Get End Property Public Sub New(ByVal Nome As String, ByVal Descricao As String) _nome = Nome _descricao = Descricao End Sub Public Overrides Function ToString() As String Return _nome End Function End Class Edited February 14, 2016 at 02:05 PM by vikcch
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