Databinding Listbox errors

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.aspx?scid=kb;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...
 
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
 
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.
 
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 asdim 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
 

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

Back
Top