Reputation: 95
I am trying to change what is visible in my user control by checking some checkbox's in my form (the parent). I have tried changing it directly in the parent form and in a function on the child's side. From debug the property is being changed but then after the call the property seems to reset to the default value.
My code on the parent side
public partial class Program: DevExpress.XtraBars.Ribbon.RibbonForm
{
public Program()
{
InitializeComponent();
}
public class GlobalVariables
{
public static string categoryID = "1";
public static string currentPage = "Campus";
}
private void ribbonControl1_MouseDown(object sender, MouseEventArgs e)
{
RibbonControl ribbon = sender as RibbonControl;
RibbonHitInfo hitInfo = ribbon.CalcHitInfo(e.Location);
if (hitInfo.HitTest == RibbonHitTest.PageHeader)
{
System.Diagnostics.Debug.WriteLine(hitInfo.Page.Name + "");
pnlPanel.Panel2.Controls.Clear();
if(hitInfo.Page.Name == "Campus")
{
var Campus = new WindowsFormsApplication1.Campus();
pnlPanel.Panel2.Controls.Add(Campus);
GlobalVariables.currentPage = "Campus";
}
else if (hitInfo.Page.Name == "Report")
{
var Report = new WindowsFormsApplication1.Report();
pnlPanel.Panel2.Controls.Add(Report);
GlobalVariables.currentPage = "Report";
}
else if (hitInfo.Page.Name == "Admin")
{
var Admin = new WindowsFormsApplication1.Admin();
pnlPanel.Panel2.Controls.Add(Admin);
GlobalVariables.currentPage = "Admin";
}
}
}
private void Program_Load(object sender, EventArgs e)
{
var Campus = new WindowsFormsApplication1.Campus();
pnlPanel.Panel2.Controls.Add(Campus);
List<string> Category = GenerateCategory();
for(int j = 0; j<= Category.Count(); j++)
{
krpList.Items.Add(Category[j + 1]);
krpValue.Items.Add(Category[j]);
j++;
}
}
public void krpList_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedIndex = krpList.SelectedIndex;
krpValue.SelectedIndex = selectedIndex;
GlobalVariables.categoryID = krpValue.SelectedItem + "";
System.Diagnostics.Debug.WriteLine(krpValue.SelectedItem);
Reset();
}
public void Reset()
{
var Campus = new WindowsFormsApplication1.Campus();
pnlPanel.Panel2.Controls.Clear();
pnlPanel.Panel2.Controls.Add(Campus);
}
private void chkDisplay_EditValueChanged(object sender, EventArgs e)
{
string displayInfo = "";
var Campus = new WindowsFormsApplication1.Campus();
displayInfo = chkDisplay.Text;
Campus.UpdateAudit(displayInfo);
Campus.treeList1.ClearNodes();
}
}
}
User control code
public void UpdateAudit(string displayInfo) //Child Method
{
treeList1.ClearNodes(); //Adjusting property on user control element
treeList1.Columns[1].VisibleIndex = 1;
treeList1.Columns[2].VisibleIndex = 2;
//...more code similar to above
}
Any help would be appreciated.
Upvotes: 0
Views: 1254
Reputation: 2220
well, here is the problem, you are using multiple instances of same form. you should rather create a single instance and use it .
public partial class Program: DevExpress.XtraBars.Ribbon.RibbonForm {
UserControl Campus = null;
public Program()
{
InitializeComponent();
Campus = new WindowsFormsApplication1.Campus();
}
private void Program_Load(object sender, EventArgs e) {
// remove this object creation
//var Campus = new WindowsFormsApplication1.Campus();
pnlPanel.Panel2.Controls.Add(Campus);
...
}
public void Reset() {
// remove this object creation
// var Campus = new WindowsFormsApplication1.Campus();
}
private void chkDisplay_EditValueChanged(object sender, EventArgs e) {
string displayInfo = "";
// remove this object creation
// var Campus = new WindowsFormsApplication1.Campus();
}
private void ribbonControl1_MouseDown(object sender, MouseEventArgs e)
{
...
if(hitInfo.Page.Name == "Campus")
{
// remove this object creation
//var Campus = new WindowsFormsApplication1.Campus();
}
...
}
}
Upvotes: 1