setting usercontrol's datasource that is same as parent form
-
hi i m newbie on C# I have created a usercontrol that has a datagridview i use this control on my parent form, the problem is that i want to set the datasource property of my usercontrol the same as my parent form so that gridview shows the data of the datatable of parent form's dataset' my coding is like this is it work fine public partial class UserControl1 : UserControl { public DataSet ds; public DataTable dt; public UserControl1() { InitializeComponent(); } public dataset ds { set { this.ds = value; this.dgvSearch.datasource = ds; } get { return ds; } } public DataTable dt { set { this.dt = value; this.dgvSearch.DataMember = dt; } get { return dt; } } or m missing something any sort of help will be highly appreciated Thanks
-
hi i m newbie on C# I have created a usercontrol that has a datagridview i use this control on my parent form, the problem is that i want to set the datasource property of my usercontrol the same as my parent form so that gridview shows the data of the datatable of parent form's dataset' my coding is like this is it work fine public partial class UserControl1 : UserControl { public DataSet ds; public DataTable dt; public UserControl1() { InitializeComponent(); } public dataset ds { set { this.ds = value; this.dgvSearch.datasource = ds; } get { return ds; } } public DataTable dt { set { this.dt = value; this.dgvSearch.DataMember = dt; } get { return dt; } } or m missing something any sort of help will be highly appreciated Thanks
saneng wrote:
public DataSet ds; public DataTable dt;
Make these variables to private.
saneng wrote:
public dataset ds { set { this.ds = value; this.dgvSearch.datasource = ds; } get { return ds; } }
Change the name of this property as you variable and property names are same.
public Dataset ControlDataSet
{
set
{
this.ds = value;
this.dgvSearch.datasource = ds;
}
get
{
return ds;
}
}All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions