Fill ListBox (from Class 'ThisAddIn')

  • Thread starter Thread starter Seran
  • Start date Start date
S

Seran

Hello,
I have a sorteddirectory (class ThisAddIn) and would like to populate the
data to a listbox on a winform.
I have created a instance of the form, but how can I get the listbox control
for adding data?

Thanks in advance,
Seran
 
Hi Seran,

I'm not entirely sure I understand your problem, if you have created the
Form, surely you have created the ListBox as well? To populate the ListBox
you can use its DataSource property.

If you wonder how you can display the SortedDictionary you can do so using a
BindingSource.

ThisAddIn addIn = new ThisAddIn();
BindingSource bs = new BindingSource(addIn, "Dictionary");
listBox1.DataSource = bs;
listBox1.DisplayMember = "Value"; // Remove this line to display
both Key and Value

....

public class ThisAddIn
{
public System.Collections.Generic.SortedDictionary<int, string>
Dictionary { get; set; }
public ThisAddIn()
{
Dictionary = new
System.Collections.Generic.SortedDictionary<int, string>();
Dictionary.Add(1, "One");
Dictionary.Add(2, "Two");
Dictionary.Add(3, "Three");
}
}
 
Back
Top