473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Databinding Listbox errors

I've got a snippet of code that's throwing up an exception:
"Can't modify the Items collection when the DataSource property is set."

I've tried the resolutions in
http://support.microsoft.com/default...;en-us;Q316568 with no luck,
as well as going through the few results on Google.

For point of reference, my code looks a little like:

m_UserList = m_BrUser.LoadList(False)
lstUsers.Sorted = True
lstUsers.ValueMember = "UserId"
lstUsers.DisplayMember = "DisplayName"
lstUsers.DataSource = m_UserList.Tables("us_Users")

Which occurs after the call to InitializeComponent() in the constructor of
the form.

Any ideas what could be causing this? It's stumped me for the best part of a
day already...
Nov 21 '05 #1
4 1050
Rowland,

Probably you have using the designer set some items in the item collection
of that what I assume is a listbox

I hope this helps?

Cor

"Rowland Shaw" <Ro*********@discussions.microsoft.com>
...
I've got a snippet of code that's throwing up an exception:
"Can't modify the Items collection when the DataSource property is set."

I've tried the resolutions in
http://support.microsoft.com/default...;en-us;Q316568 with no
luck,
as well as going through the few results on Google.

For point of reference, my code looks a little like:

m_UserList = m_BrUser.LoadList(False)
lstUsers.Sorted = True
lstUsers.ValueMember = "UserId"
lstUsers.DisplayMember = "DisplayName"
lstUsers.DataSource = m_UserList.Tables("us_Users")

Which occurs after the call to InitializeComponent() in the constructor of
the form.

Any ideas what could be causing this? It's stumped me for the best part of
a
day already...

Nov 21 '05 #2
Thanks for taking the time to reply, but unfortunatly, this is not the case,
I did soem further investigation; I did find the exception was being thrown
in the call to the form's Show() method (which I have not overridden)

I did try moving the code into the form's onload handler, but with no success.

Removing the Sorted attribute make it work flawlessly

I fear the only work around will be to duplicate the stored procedure I'm
calling, and do the sorting there, but I would prefer to be able to reuse the
data more elegantly.
"Cor Ligthert" wrote:
Probably you have using the designer set some items in the item collection
of that what I assume is a listbox
"Rowland Shaw" <Ro*********@discussions.microsoft.com>
I've got a snippet of code that's throwing up an exception:
"Can't modify the Items collection when the DataSource property is set."

I've tried the resolutions in
http://support.microsoft.com/default...;en-us;Q316568 with no
luck,
as well as going through the few results on Google.

For point of reference, my code looks a little like:

m_UserList = m_BrUser.LoadList(False)
lstUsers.Sorted = True
lstUsers.ValueMember = "UserId"
lstUsers.DisplayMember = "DisplayName"
lstUsers.DataSource = m_UserList.Tables("us_Users")

Which occurs after the call to InitializeComponent() in the constructor of
the form.

Any ideas what could be causing this? It's stumped me for the best part of
a day already...


Nov 21 '05 #3
Rowland,

I just did give you the most normal answer on this.
In my opinion is it better that when you want it sorted just place a
dataview between it.

Something as
> m_UserList = m_BrUser.LoadList(False)
> lstUsers.Sorted = True
> lstUsers.ValueMember = "UserId"
> lstUsers.DisplayMember = "DisplayName"

dim dvUsers = m_Userlist.Tables("us_Users")
dvUsers.sort = "DisplayName"
lstUsers.DataSource = dvUsers

In my opinion much nicer and I think that this helps better.

Cor
Nov 21 '05 #4
doh, and delete that sord
> m_UserList = m_BrUser.LoadList(False)
> lstUsers.ValueMember = "UserId"
> lstUsers.DisplayMember = "DisplayName"

dim dvUsers = m_Userlist.Tables("us_Users")
dvUsers.sort = "DisplayName"
lstUsers.DataSource = dvUsers

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox),...
1
by: Stephen | last post by:
I have a form with a ListBox and would like to set the DataSource property at design-time but I can't seem to declare any kind of variable that will show up in the list. I have tried a traditional...
1
by: amar shukla | last post by:
hi all, i have a problem, i am coding a problem, which is suppose to fetch records from database into a combobox and there after based on the selection of value it has to proceed further , i...
3
by: Alec MacLean | last post by:
Hi everyone, I have a ComboBox that when changed, calls a method to change the content of a ListBox. I'm also using the Listbox's SelectedIndexChanged event to change other control values on...
2
by: musosdev | last post by:
Hi guys I have an asp:ListBox on my form, which I'm populating with a DataReader, using DataSource/DataBind. The problem is that the main field I want to use for DataTextField, "Company" in...
6
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am...
0
by: bnolingberg | last post by:
Hi all. I've been stuck on this problem for a while (I'm a newbie). I have a listbox with several collection objects, some of them being identical. When one of the collection items is selected...
9
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback)....
3
by: Peter | last post by:
Hi! I am having some very strange behavior with my databound controls. It's taken a long time to isolate exactly what is provoking the problem, but I'm still leagues away from solving it. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.