jueves, 25 de noviembre de 2010

Combo Box múltiple en Visual Studio

A esto me refiero con un combo que tenga dos elementos ejemplo el código y la descripción, que se muestre solo la descripción y obtengamos el código de esa selección.
Lo primero que hacemos es definir una nueva clase en nuestro proyecto Ej. ClassComboMultiple, el cual tiene un value y una descripción (adjunto el codigo):
Public Class ClassComboMultiple
Public Value As Object
Public Description As String

Public Sub New(ByVal NewValue As Object, ByVal NewDescription As String)
Value = NewValue
Description = NewDescription
End Sub

Public Overrides Function ToString() As String
Return Description
End Function
End Class

Una vez armado esto (en mi caso los valores son obtenidos de una tabla de un sqlce) solo tenemos que cargar los datos:

vL_ConexionMobil = New SqlCeConnection(vL_ArchivoMobil)
StrSql = "Select * from " & NombreTabla
MobilDataAdapter = New SqlCeDataAdapter(StrSql, vL_ConexionMobil)
Dim MobilTable As New DataTable
MobilDataAdapter.Fill(MobilTable)
For Each row As DataRow In MobilTable.Rows
FrmVenta.ComboBox1.Items.Add(New ClassComboMultiple(row.Item("Codigo"), row.Item("Razon").ToString))
Next

Y listo esto cargara en nuestro combo box los datos.
Para mostrar el dato seleccionado solo debemos hacer:

Me.CodigoCliente = CType(ComboBox1.SelectedItem, ClassComboMultiple).Value

Espero que les sirva.

7 comentarios:

  1. What's Taking place i am new to this, I stumbled upon this I have discovered It absolutely helpful and it has aided me out loads. I hope to give a contribution & help other users like its aided me. Great job.

    Review my blog post - chestfatburner.com

    ResponderEliminar
  2. Fantastic goods from you, man. I've be mindful your stuff previous to and you're simply too great.
    I actually like what you have obtained right here, really like what you're saying and the best way through which you say it. You are making it enjoyable and you continue to care for to keep it wise. I cant wait to learn much more from you. That is really a great website.

    Also visit my blog post Unwanted effects associated with androgen hormone or the male growth hormone products – Gynecomastia

    ResponderEliminar
  3. Hello, I log on to your blogs regularly. Your story-telling style is
    witty, keep it up!

    my page Building Interior Upper body?

    ResponderEliminar
  4. You can certainly see your expertise in the
    work you write. The arena hopes for more passionate
    writers like you who are not afraid to say how they
    believe. Always go after your heart.

    my weblog: Alternative Treatments With Regard To Gynecomastia

    ResponderEliminar
  5. I have been browsing on-line more than three hours these days, but I never discovered
    any attention-grabbing article like yours. It is pretty worth sufficient
    for me. In my opinion, if all webmasters and bloggers made excellent content material as
    you did, the web shall be much more helpful than ever before.


    My blog; So how exactly does doing exercises impact parts of muscle tissue ?

    ResponderEliminar
  6. If you would like to take a good deal from this article then you have to apply such methods to
    your won weblog.

    Here is my weblog ... Types of Gynecomastia

    ResponderEliminar
  7. Hi colleagues, nice article and fastidious arguments commented here, I am in fact enjoying by these.



    Also visit my page ... The particular results associated with gynecomastia

    ResponderEliminar