|
-
Apr 25th, 2009, 09:56 PM
#1
Thread Starter
Frenzied Member
ListBox Refresh DataSource?
I want to refresh my list because right now I have a custom List with a sub List and I want to have each sub list entry as a separate line.
Code:
class WDFFileList : List<WDFFile>, System.ComponentModel.IListSource
{
public bool ContainsListCollection
{
get
{
return true;
}
}
public System.Collections.IList GetList()
{
List<WDFEntry> entries = new List<WDFEntry>();
foreach (WDFFile f in this)
{
foreach (WDFEntry e in f.Entries)
{
entries.Add(e);
}
}
return entries;
}
}
Now this "works" as in when I first set the databind GetList() is called. But how do I refresh the datasource? Like when I add some entries I want to update the listbox.
I have tried
Code:
UsageList.DataSource = null;
UsageList.DataSource = Files;
But GetList() wasn't called.
Just tried this
Code:
class WDFFileList : List<WDFFile>, System.ComponentModel.IListSource
{
public List<WDFEntry> Entries = new List<WDFEntry>();
public void Refresh()
{
Entries.Clear();
foreach (WDFFile f in this)
{
foreach (WDFEntry e in f.Entries)
{
Entries.Add(e);
}
}
}
public bool ContainsListCollection
{
get
{
return true;
}
}
public System.Collections.IList GetList()
{
return Entries;
}
}
Still didn't update.
How do you update a custom datasource? Or am I approaching this wrong?
-
Apr 26th, 2009, 12:34 AM
#2
Re: ListBox Refresh DataSource?
You should inherit BindingList instead of List and then you can call ResetBindings, although I've never tried it with a custom IListSource. The problem I see is that your class is an IList AND and IListSource, which may be causing its IListSource nature to be ignored and its IList nature used. Generally a class won't implement both. To avoid this potential conflict you might want to hide your List inside rather than inheriting, so that you class will only implement IListSource.
-
Apr 26th, 2009, 01:16 AM
#3
Thread Starter
Frenzied Member
Re: ListBox Refresh DataSource?
 Originally Posted by jmcilhinney
You should inherit BindingList instead of List and then you can call ResetBindings, although I've never tried it with a custom IListSource. The problem I see is that your class is an IList AND and IListSource, which may be causing its IListSource nature to be ignored and its IList nature used. Generally a class won't implement both. To avoid this potential conflict you might want to hide your List inside rather than inheriting, so that you class will only implement IListSource.
I will try BindingList.
I tried that, it gave the same result. GetList() was only called once when I set the DataSource.
-
Apr 26th, 2009, 02:05 AM
#4
Re: ListBox Refresh DataSource?
So try the rest of my advice. Implementing IList and IListSource in the same class is asking for trouble because an IListSource is supposed to be the source of a list, not a list itself.
-
Apr 26th, 2009, 12:09 PM
#5
Thread Starter
Frenzied Member
Re: ListBox Refresh DataSource?
 Originally Posted by jmcilhinney
So try the rest of my advice. Implementing IList and IListSource in the same class is asking for trouble because an IListSource is supposed to be the source of a list, not a list itself.
But with BindingSource can you give the ListBox a custom list?
-
Apr 26th, 2009, 04:30 PM
#6
Thread Starter
Frenzied Member
Re: ListBox Refresh DataSource?
Code:
class WDFEntryList : System.ComponentModel.BindingList<WDFEntry>
{
}
class WDFFileList : List<WDFFile>
{
public WDFEntryList Entries = new WDFEntryList();
public void Refresh()
{
Entries.Clear();
foreach (WDFFile f in this)
{
foreach (WDFEntry e in f.Entries)
{
Entries.Add(e);
}
}
}
}
It "works" but it takes an awful long time to load because I think it is rendering each time it adds an item. Is there a way to pause the rendering?
-
Apr 26th, 2009, 04:38 PM
#7
Thread Starter
Frenzied Member
Re: ListBox Refresh DataSource?
Okay well this works and doesn't take 10-20 seconds to load.
Code:
class WDFEntryList : List<WDFEntry>, System.ComponentModel.IListSource
{
public bool ContainsListCollection
{
get { return true; }
}
public System.Collections.IList GetList()
{
return this;
}
}
class WDFFileList : List<WDFFile>
{
public WDFEntryList Entries = new WDFEntryList();
public void Refresh()
{
Entries.Clear();
foreach (WDFFile f in this)
{
foreach (WDFEntry e in f.Entries)
{
Entries.Add(e);
}
}
}
}
Code:
UsageList.DataSource = null;
Files.Refresh();
UsageList.DataSource = Files.Entries;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|