SortedList bind to datagrid

G

Guest

How does one bind a SortedList to anything. If it cant be done why would
anyone ever even use a sortedlist?

We are currently (via business objects that use interfaces etc) binding
gridviews to List<T> type with zero problem which was an upgrade from our
previous methodology of doing the exact same thing with Arraylists.
However now using SortedList it doesnt work becuase it doesnt have an index
but rather a "key" which in our case is type string.

What really confuses me is that I dont understand why anyone would ever use
a SortedList<T> if it cant be bound to anything which means I am clearly
missing the point of SortedList<T>

Thanks
 
G

Guest

nevermind!

I needed to access an index value of the sorted list and its
SortedList.Values(index)

that was all I was trying to find and I didnt even know it.
 
G

Guest

Hi Sean,
when you bind to the sorted list you just need to specify what you want to
display the Key or the Value. Below is an example of a sorted list being
databound to a combo box and displaying the Value:

SortedList<int, string> myList = new SortedList<int, string>();
myList.Add(1, "one");
myList.Add(2, "two");
myList.Add(3, "three");

BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = myList;

comboBox1.DisplayMember = "Value";
comboBox1.DataSource = bindingSource;

Hope that helps
Mark Dawson
http://www.markdawson.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top