Witam,
Pisze program w którym podpinam listę obiektów pod DataSource komponentu CheckedListBox.
Klasa którą podpinam wygląda tak:
public class TargetControl
{
private List<TargetTest> listTargetClass = new List<TargetTest>();
problem w tym, że interesuje mnie tak naprawdę lista z tej klasy:
public class TargetTest
{
private string nameClass = string.Empty;
private string dll = string.Empty;
private List<string> functions = new List<string>;... propertisy
Podpinam, więc obiekt klasy TargetTest po to by wyciągnąć listę List<string> functions.
Robię to tak:
((ListBox)this.checkedListBox2).DataSource = null;
((ListBox)this.checkedListBox2).DataSource = controlTest.ListTargetClass;
((ListBox)this.checkedListBox2).DisplayMember = "Function";
((ListBox)this.checkedListBox2).ValueMember = "Function";
Niestety w ten sposób otrzymuję Exception.
W jaki sposób mogę podpiąć listę stringów korzystając z listy tych obiektów? Mogę to zrobić inaczej?
Aktualnie poradziłem sobie poprzez dziedziczenie:
public class TargetTest
{
private string nameClass = string.Empty;
private string dll = string.Empty;public class TargetTestFunctions : TargetTest
{
private string function = string.Empty;public string Function { get { return this.function; } }
public class TargetControl
{
private List<TargetTest> listTargetClass = new List<TargetTest>();
private List<TargetTestFunctions> listTargetFunctions = new List<TargetTestFunctions>();
jednak wydaje mi się, że da się to zrobić lepiej.
Proszę o pomoc.
Pozdrawiam,