listbox.valuemember throws exception

-1

I have this simple code:

 ListBox1.DataSource = MGlobals.UserList

ListBox1.DisplayMember = "Nome"

ListBox1.ValueMember = "ID"

when setting .ValueMember i get "

System.ArgumentException
  HResult=0x80070057
  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.

vb.net
asked on Stack Overflow May 11, 2019 by Luís Abreu

1 Answer

0

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