This may not be CSLA specific - thinking it's a databinding thing, just thought I'd throw it out there.
I have a ListBox that is whose DataSource is a BindingSource, the BindingSource's DataSource is an Editable Root List.
If I add a single item to the ListBox, via the bo's .AddNew() method, set my properties, the new item shows up just fine.
If I attempt add items in a loop (foreach or for...), the very last item added does not show it's text. The item is there, just with empty text. I can verify this by iterating through the items and printing out the text value.
Why would the last item to be added not show it's text?
Thanks,
Mike
Thanks for the reply.
Yes, I am adding the item to the collection and then setting the text. More specifically, I'm setting the public property of the new object. That property does call PropertyHasChanged - stepped through the code to be sure. This is the same property that the ListBox's DisplayMember is set to (RoleName in this example).
Looking a little more carefully at this, it's not related to the looping thing. If I add an item one by one, sometimes the text appears, and sometimes it doesn't. Strange.
Here's the code if it makes a difference. I'm starting to think I'm just doing something wrong.
// Get the selected item. ListViewItem item = lvRoleList.SelectedItems[0]; // Add new role to the assigned list. EmployeeEditableChild employee = (EmployeeEditableChild)employeeEditableRootListBindingSource.Current; EmployeeRoleEditableChild employeeRole = employee.EmployeeRoles.AddNew();employeeRole.RoleFK =
new Guid(item.Name);employeeRole.EmployeeFK = employee.PK;
employeeRole.RoleName = item.Text;
// Remove from all roles list.item.Remove();
Regards,
Mike
Cool, thanks Brian, that did the trick.
I set the ListBox's .DataSource to null, then back to the BindingSource - also had to reset the .DisplayMember so my wanted property is displayed.
Thanks!
Mike
From: Michael Hildner [mailto:cslanet@lhotka.net]
Sent: Thursday, August 24, 2006 3:12 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Adding objects to a ListBox in a loopCool, thanks Brian, that did the trick.
I set the ListBox's .DataSource to null, then back to the BindingSource - also had to reset the .DisplayMember so my wanted property is displayed.
Thanks!
Mike
Thanks, that works as well - a couple less lines of code.
Thanks,
Mike
Copyright (c) Marimer LLC