Contact

admin

About Me · Send mail to the author(s) E-mail · Twitter

At GROSSWEBER we practice what we preach. We offer trainings for modern software technologies like Behavior Driven Development, Clean Code and Git. Our staff is fluent in a variety of languages, including English.

Feed Icon

Tags

Open Source Projects

Archives

Blogs of friends

Now playing [?]

Error retrieving information from external service.
Audioscrobbler/Last.fm

ClustrMap

Binding a StringCollection to a ListBox

Posted in Geek Mode at Wednesday, October 19, 2005 6:04 PM W. Europe Daylight Time

During the development of my Smart Tag I needed to bind a StringCollection to a ListBox on a Windows Form. The initial databinding itself worked fine, i.e. the original contents of the collection showed up. I even could add items to the collection or remove them. The UI remained unchanged, however: Basic collections don't support two-way databinding as I discovered.

private void btnAdd_Click(object sender, System.EventArgs e)
{
    stringCollection1.Add(
"foo");
    
    
// Use the currency manager to sync up the listbox.
    CurrencyManager cm = (CurrencyManager) this.listBox1.BindingContext[stringCollection1];
    
    
if (cm != null)
    {
        cm.Refresh();
    }
}

The same applies for element updates and deletion.

Now playing: MC Conrad - Logical Progression Level 4 (Limited Edition) - Cool vertigo

All comments require the approval of the site owner before being displayed.
(will show your gravatar icon)
 
[Captcha]Enter the code shown (prevents robots):

Live Comment Preview