Jump to content

Como carregar uma combobox com um modulo


Recommended Posts

Tenho uma combobox e queria carrega-la com dados através de um módulo, mas tenho um problema o modulo funciona não consigo é passar os dados para a combobox.

comb(n)
        cboxComb = n

Alguem me pode ajudar??

Link to post
Share on other sites

quando a form abre

Dim n As New ComboBox
comb (n)

O modulo

 Sub comb(ByRef n)
        n.DisplayMember = "Nome"
        n.ValueMember = "ID"

        'Simular uma datatable, imaginando que vem da base de dados
        Dim DT As New DataTable
        DT.Columns.Add("ID")
        DT.Columns.Add("Nome")
        DT.Rows.Add(New Object() {0, ""})
        DT.Rows.Add(New Object() {1, "Gasolina/95"})
        DT.Rows.Add(New Object() {2, "Gasoleo"})
        DT.Rows.Add(New Object() {3, "Gasolina/GForce"})
        DT.Rows.Add(New Object() {4, "Gasóleo/GForce"})
        n = DT
    End Sub 

depois na form:

 cboxComb = n

Link to post
Share on other sites

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.