views:

32

answers:

1

When I change the datasource of my Listbox all items are cleared, when loading new data into this Listbox it stays clear. I have another ListBox right new to this one with the same refresh code but that one refreshes perfectly.

    private void RefreshContacts()
    {
        this.ListContacts.DataSource = null; 
        this.ListContacts.DataSource = this.contacts;
        this.BoxCountContacts.Text = this.ListContacts.Items.Count.ToString();
    }

Anyone have an idea how to fix the listbox from being cleared and bugged?

Here is the full refresh codes of the two listboxes

    private Contact[] contacts, feed; private Boolean isFeed;

    internal ArcFeed()
    { 
        this.InitializeComponent();
        this.contacts = this.feed = new Contact[0]; 
    }
    private void RefreshForm(Boolean isFeed)
    { 
        if (isFeed)
        { 
            this.RefreshFeed();
        } 
        else 
        { 
            this.RefreshContacts();
        } 
    }
    private void RefreshContacts()
    {
        this.ListContacts.DataSource = null;         
        this.ListContacts.DataSource = this.contacts;
        this.BoxCountContacts.Text = this.ListContacts.Items.Count.ToString();
    }
    private void RefreshFeed()
    {
        this.ListFeed.DataSource = null; 
        this.ListFeed.DataSource = this.feed;
        this.BoxCountFeed.Text = this.ListFeed.Items.Count.ToString();
    }
    private void OpenFile()
    {
        if (this.isFeed)
        { 
            this.BoxFileFeed.Text = this.DialogOpen.FileName;
            this.feed = ArcBuzz.Load(this.DialogOpen.FileName);
        }
        else
        {
            this.BoxFileContacts.Text = this.DialogOpen.FileName;
            this.contacts = ArcBuzz.Load(this.DialogOpen.FileName); 
        }
        this.RefreshForm(this.isFeed);
    }

All code is debugged and follows it's course properly, I don't see any errors, the correct listbox's datasource are set and changed.

A: 

Just to make sure, have you checked that there are actually items in the contacts collection?

Also, if you've got two Listboxes, double check that you are using the right Listbox in each of the refresh code sections.

Sounds stupid, but its silly mistakes like this that get overlooked a lot of the time. With databinding its usually something small like this stopping it working.

w69rdy
Yes, it has dozens of items, but even when I set a new collection to the datasource, the listbox is unresponsive.
D. Veloper
Can you post the entire code you're using to populate and refresh it pls?
w69rdy
@w69rdy: Posted.
D. Veloper
Code looks ok to me. The only other thing I can think of is that Visual Studio has done something funny in the designer or something like that. Try deleting the list box and adding it again with the same name and see if the problem is there still
w69rdy
@w69rdy: I already did, I copied the ListFeed listbox and renamed it, no change, perhaps I can try to put the controls in a new winform because the designer code could be messed up.
D. Veloper
Try swapping the datasources round and see if the other listbox stops working. If it does then it could be a problem with the datasource.
w69rdy
@w69rdy: Nope, no change, I loaded ListFeed and ListContact datasources randomly and interchanged, so the datasources are fine.
D. Veloper