I am using Visual Studio and c#. I have a form that contains a Developer Express data-aware treelist called treelist1, which has a datasource property. I created a method to set the datasource property of the treelist:
public partial class UserControl1 : UserControl {
public UserControl1()
{
InitializeComponent();
}
public void SetTreelist1DataSource(System.Data.DataTable dataTable)
{
treeList1.DataSource = dataTable;
}
}
}
I am trying to set the dataTable property from another class:
class DataAccess
{
public static void LoadDataSource()
{
string constring = "Default";
using (SqlConnection cstr = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", cstr))
{
cmd.CommandType = CommandType.Text;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
UserControl1.SetTreelist1DataSource(dt);
}
}
}
}
}
}
}
The line UserControl1.SetTreelist1DataSource(dt); gets the compiler error, "An object reference is required for the nonstatic method, data field or property usercontrol1.settreelist1datasource(datatable)".
Any constructive help would be greatly appreciated.
Paul