Binding data to a listbox

  • Thread starter Thread starter UJ
  • Start date Start date
U

UJ

Before I even start, let me say I'm an idiot and get that out of the way.
I've search the help file, searched the newsgroups, search
support.microsoft.com and can't figure out what is wrong.

I have a listbox on a windows form that I'm attempting to bind to a
datatable. Here's the code I do:

lb_PossibleParents.DataSource = dtKitsList
lb_PossibleParents.DisplayMember = "CompanyName"

Looks like it should work right? Well it's not. The list box has row after
row that contains 'System.Data.DataRowView'

So what am I doing wrong? I'm sure it's something stupid.

I've also tried putting in a ValueMember property - and no matter what I put
in, I get an error message ( on that line ) 'Could not bind to the new
display member' even though I'm doing a ValueMemeber.

Can somebody please help me? This is driving me crazy!!!

UJ.
 
UJ,

The most made error with your first problem is that the DisplayMember with a
windowform listbox is case sensitive while with a webform listbox it is case
insensitive.

The second problem looks strange for me. However maybe you can look at this
first.

Cor
 
UJ,

When you than want some help, than I think you would show some more code,
that shows where you do that binding. As well if you have something as an
index change event what you did not protect when loading the listbox..

Cor
 
Cor,
That's the only code I have for doing anything with the list box. I haven't
even gotten to the change of index yet.

I populate the table, then attempt to bind the data to the listbox. That's
when I get the error.

UJ.
 
Thanks Cor for you help. Turned out it was an issue with the way the field
was capitalized.

UJ.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top