listbox frenzy

G

Guest

Hey all,

I was wondering if you databind to a listbox, can you at the same time have
an extra item in there like say, <new> ?

thanks,
rodchar
 
L

Lucas Tam

I was wondering if you databind to a listbox, can you at the same time
have an extra item in there like say, <new> ?

Yes. Just add the item AFTER the databind.
 
G

Guest

Hey Lucas,

when I add it like this, I get an error message.
lbDescription.DataSource = _dt
lbDescription.DisplayMember = "Description"
lbDescription.ValueMember = "CodesID"
lbDescription.Items.Add("<New>")

I get this error:
An unhandled exception of type 'System.ArgumentException' occurred in
system.windows.forms.dll

Additional information: Cannot modify the Items collection when the
DataSource property is set.
 
K

Ken Tucker [MVP]

Hi,

You have to add the item to the datasource.

Ken
-----------------
Hey all,

I was wondering if you databind to a listbox, can you at the same time have
an extra item in there like say, <new> ?

thanks,
rodchar
 
L

Lucas Tam

I get this error:
An unhandled exception of type 'System.ArgumentException' occurred in
system.windows.forms.dll

Additional information: Cannot modify the Items collection when the
DataSource property is set.

Hmm, it works with Webforms, I guess I never tried it with Winforms.

Try adding the item to the dataset ... then binding it. That should work
for sure.
 
G

Guest

Hello

I have the same problem...but i want to remove a item from listbox but not
remove it from db. the error its the same!!! I can i do this ???

Sorry but i dont understand the other answers to the problem of Rodchar

VitorJOL
 

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

is there a way to do this 4
array bound listbox 2
residual of some sort 1
listbox events 3
Access Cannot select items in listbox 1
moving listbox items 2
MDI Forms OVER Listbox 0
Moving item from 1 listbox to another listbox 3

Top