Mainform i put the function UpdatingListView
public void UpdatingListView(Bestelling orders)
{
ListViewItem lvi = new ListViewItem(orders.getDiscription());
lvi.SubItems.Add(Convert.ToString(orders.getvalue()));
lvi.SubItems.Add(Convert.ToString(orders.getPrice())+" €");
lstBesteld.Items.Add(lvi);
}
In the UserControl, i pass the mainform.
In my function where is set buttons, i have a clickEvent which passing an object
<pre> public ContrlVoorgerechten(frmHoofd frm)
{
InitializeComponent();
this.frm = frm;
AddButton addButton = new AddButton();
addButton.ClickEvent += (s,orders) =>
{
frm.UpdatingListView(orders);
};
int twintig = 17;
int honderdvijf = 135;
int tweehonderdvijf = 250;
addButton.New(this, "1.Tom-Yam", 2, twintig, "Images\\tom-yam.jpg", "8");
addButton.New(this, "2.Tom-Kha", 165, twintig, "Images\\tom-kha.jpg", "8");
addButton.New(this, "3.Wantan", 325, twintig, "Images\\legefoto.jpg", "8");
and the class where i create the buttonsi call the
EventHandler(BTNclick);
<pre lang="C#">
<pre>
public EventHandler<Bestelling> ClickEvent;
public void New(UserControl user, String text, int Location_X, int Location_Y, String stringPath, string prijs)
{
System.Windows.Forms.Button button = new System.Windows.Forms.Button
{
Text = text,
Location = new Point(Location_X, Location_Y),
Name = prijs,
TextAlign = ContentAlignment.BottomCenter,
Font = new Font("Microsoft Sans Serif", 11),
BackColor = Color.White,
Width = 150,
Height = 100,
FlatStyle = FlatStyle.Flat,
Image = System.Drawing.Image.FromFile(stringPath)
};
button.Click += new System.EventHandler(BTNclick);
user.Controls.Add(button);
}
public void BTNclick(object sender, EventArgs e)
{
System.Windows.Forms.Button clickedbtn = sender as System.Windows.Forms.Button;
Bestelling orders = new Bestelling();
orders.setDiscription(clickedbtn.Text);
orders.setPrice(Convert.ToInt32(clickedbtn.Name));
orders.setAantal(1);
ClickEvent.Invoke(this,orders);
}
Thank you and hope somebody else can learn from it.