listbox.valuemember throws exception


I have this simple code:

 ListBox1.DataSource = MGlobals.UserList

ListBox1.DisplayMember = "Nome"

ListBox1.ValueMember = "ID"

when setting .ValueMember i get "

  Message=Não é possível vincular ao novo membro de apresentação.
Nome do parâmetro: newDisplayMember


debugging i found ListBox1.ValueMember holding "" and ListBox1.DisplayMember holding "ID". Can anyone help me? Thanks.
asked on Stack Overflow May 11, 2019 by Luís Abreu

1 Answer


Assuming your datasource Does have the Nome and ID columns, you could try changing the order to something like this:

ListBox1.DisplayMember = "Nome"
ListBox1.ValueMember   = "ID"
ListBox1.DataSource    = MGlobals.UserList
answered on Stack Overflow May 11, 2019 by MorenajeRD

User contributions licensed under CC BY-SA 3.0