WinForm Bound ListBox not showing all items when DisplayMember set

  • Thread starter Thread starter jeepfan
  • Start date Start date
J

jeepfan

Guest
I cant seem to figure out why this code wont work:

public FormMain()
{
this.InitializeComponent();
}

public FormMain(FormMainPresenter presenter) : this()
{
this.presenter = presenter;

this.listBoxProcessSteps.DisplayMember = "PageViewModel.PageTitle";

this.bindingSource = new BindingSource { DataSource = this.presenter.Pages };

// TODO: Why is ListBox only showing 1st page, not second. If I dont set display member, it shows both!
this.listBoxProcessSteps.DataSource = this.bindingSource;

this.presenter.CurrentPageChanged += this.FormMainViewModel_CurrentPageChanged;
}



This is a MVP-VM Wizard-like application, where I am attempting to display a list of all of the pages in the wizard. Pages is of type "Collection<WizardPagePresenterBase>", where WizardPagePresenterBase looks something like:

public abstract class WizardPagePresenterBase : IDisposable
{
public WizardPageViewBase View { get; set; }

public WizardPageViewModel PageViewModel { get; set; }

#region IDisposable implementation

public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

protected abstract void Dispose(bool disposing);

#endregion
}



and WizardPageViewModel looks something like:

public class WizardPageViewModel : ViewModelBase
{
public string PageTitle { get; set; }

public bool IsValid { get; set; }
}



I have added 2 pages to my FormMainPresenter, and both of them have their PageTitle set to a valid string.

If I do not set the DisplayMember property of the list, the ToString result for both pages is displayed in the ListBox as expected. However, if I set the DisplayMember property to "PageViewModel.PageTitle", then the ListBox contains only the first PageTitle. There are no other items in the ListBox. I have set a breakpoint and verified that both PageTitles have valid strings. So, I am confused as to why setting the DisplayMember breaks the functionality.

Thanks for any help you can provide,

Todd

Continue reading...
 
Back
Top