Jeremy
Jeremy
CC#
Created by Jeremy on 4/17/2023 in #help
❔ WinForms Refreshing parent Flowpanel issues
cartForm: runs a method called loadItems taking an array of items as a parameter. This populates a flowpanel with a user control template called cartMenuItems. The cartMenuItems template has a X button in the top right. On click I want it to remove an item from the array, and then delete the flowpanel and re-run loadItems to update the panel. The issue is making it so that onclick I delete the flowpanel and loadItems to update the panel.
public partial class cartForm : Form{
public cartForm(){
public void loadItems()
{
List<Item> itemList = new List<Item>();
itemList.AddRange(Program.activeUser.getCart());
for (int i =0; i<itemList.Count();i++)
{
{
cartMenuItem cartMenuItem = new cartMenuItem(itemList.ElementAt(i), getThisForm("cartForm"));
cartMenuItem.Text = ""+ i;
flowLayoutPanel1.Controls.Add(cartMenuItem);
}
}
}
}
}
public partial class cartForm : Form{
public cartForm(){
public void loadItems()
{
List<Item> itemList = new List<Item>();
itemList.AddRange(Program.activeUser.getCart());
for (int i =0; i<itemList.Count();i++)
{
{
cartMenuItem cartMenuItem = new cartMenuItem(itemList.ElementAt(i), getThisForm("cartForm"));
cartMenuItem.Text = ""+ i;
flowLayoutPanel1.Controls.Add(cartMenuItem);
}
}
}
}
}
public partial class cartMenuItem : UserControl
{
public cartMenuItem(Item item)
{
InitializeComponent();
}

private void removeBtn_Click(object sender, EventArgs e)
{
Program.activeUser.removeFromCart(this.Text);
cf.refreshPanel();

//refresh visual list.
cf = new cartForm(new string[] { }, Program.activeUser);
}
}
public partial class cartMenuItem : UserControl
{
public cartMenuItem(Item item)
{
InitializeComponent();
}

private void removeBtn_Click(object sender, EventArgs e)
{
Program.activeUser.removeFromCart(this.Text);
cf.refreshPanel();

//refresh visual list.
cf = new cartForm(new string[] { }, Program.activeUser);
}
}
2 replies