Hi, i have a class which has a property which is a list of items. I
want to be able to set this item list from a set of items (in this case
list2 as shown in the code below) from a drop down combo box. This will
allow me to enter valid items in a seperate form, then when adding a
new Class1 object i can select from one of the valid Class2 items in
the dropdown list. I hope this makes sense, i have got partway there
but i have lost synchronisation and i dont think the code is correct. I
have posted some of the code below, and posted the full project source
at www.monsterserve.net/test.zip
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
static public BindingList<Class1> list = new
BindingList<Class1>();
static public BindingList<Class2> list2 = new
BindingList<Class2>();
public Form1()
{
InitializeComponent();
list2.Add(new Class2("bill"));
list2.Add(new Class2("fred"));
m_Class1BindingSource.DataSource = list;
m_Class2BindingSource.DataSource = m_Class1BindingSource;
m_Class2BindingSource.DataMember = "MyClass";
nameDataGridViewTextBoxColumn1.DataSource = list2;
nameDataGridViewTextBoxColumn1.DisplayMember = "Name";
}
}
public class Class2
{
string m_Name;
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
public Class2(string name)
{
Name = name;
}
}
public class Class1
{
public Class1()
{
m_Class2 = Form1.list2[0];
}
string m_Name;
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
Class2 m_Class2;
public Class2 MyClass
{
get { return m_Class2; }
set { m_Class2 = value; }
}
}
}
I would also like to have a list, where i can use a combobox to select
from a set of valid pre-existing items. I have seen from the book "Data
Binding With Windows Forms 2.0" on chapter 9 it almost does what i want
but there is not preexisting list.
Any pointers much appreciated, with my newb skills i am very stuck!!
Cheers,
Chris