By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

listbox frenzy

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"=?Utf-8?B?cm9kY2hhcg==?=" <ro*****@discussions.microsoft.com> wrote in
news:3A**********************************@microsof t.com:
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.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #2

P: n/a
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.
"Lucas Tam" wrote:
"=?Utf-8?B?cm9kY2hhcg==?=" <ro*****@discussions.microsoft.com> wrote in
news:3A**********************************@microsof t.com:
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.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #3

P: n/a
Hi,

You have to add the item to the datasource.

Ken
-----------------
"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
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
Nov 21 '05 #4

P: n/a
"=?Utf-8?B?cm9kY2hhcg==?=" <ro*****@discussions.microsoft.com> wrote in
news:10**********************************@microsof t.com:

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.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #5

P: n/a
10-4.

"Ken Tucker [MVP]" wrote:
Hi,

You have to add the item to the datasource.

Ken
-----------------
"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
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

Nov 21 '05 #6

P: n/a
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

"rodchar" wrote:
10-4.

"Ken Tucker [MVP]" wrote:
Hi,

You have to add the item to the datasource.

Ken
-----------------
"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
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

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.