title: C# dynamically add button and send event args with it
body: <p>The answer would be very easy I think, but I can't find it...</p>
  
  <p>I've got a listview programmed this way:</p>
  
  <pre><code>ListView board = new ListView();
  
  board.Bounds = new Rectangle(new Point(0, 0), new Size(this.Width, this.Height));
  
  board.View = View.Details;
  board.LabelEdit = false;
  board.AllowColumnReorder = false;
  board.GridLines = true;
  
  //textPieces 0 = Van 1 = Titel 2 = Ontvangen 3 = groote
  
  board.Columns.Add(" Afzender ", -10, HorizontalAlignment.Center);
  board.Columns.Add(" Titel ", -10, HorizontalAlignment.Center);
  board.Columns.Add(" Ontvangen ", -10, HorizontalAlignment.Center);
  board.Columns.Add(" Groote ", -10, HorizontalAlignment.Center);
  board.Columns.Add(" Bekijken ", -10, HorizontalAlignment.Center);
  
  for (int c = 0; c &lt; new_message_counter; c++)
  {
      ListViewItem item = new ListViewItem(berichten_verzameling[c, 0], 0);
      item.SubItems.Add(berichten_verzameling[c, 1]);
      item.SubItems.Add(berichten_verzameling[c, 2]);
      item.SubItems.Add(berichten_verzameling[c, 3]);
      Button dynamicbutton = new Button();
      dynamicbutton.Text = "Bekijk dit bericht";
      dynamicbutton.Name = "show_all_number_" + c;
      item.SubItems.Add(dynamicbutton);
      board.Items.Add(item);
  }
  
  groupBox1_all_message.Controls.Add(board);
  </code></pre>
  
  <p>As some of you probably already saw, there is an error... because this doesn't work: (            item.SubItems.Add(dynamicbutton);)</p>
  
  <p>So my first question is how can I show the button on the same line of the other info.</p>
  
  <p>Also, how can I make an eventhandler for all these buttons dynamically, and send some arguments with it...</p>
  
  <p>Like in html / javascript it was something like :</p>
  
  <pre><code>&lt;button OnClick="DoStuff(5,true);"&gt;do it!&lt;/button&gt;
  </code></pre>
  
  <p>But how can I do this in in C#?</p>
  
  <p>Thanks in advance
  TWCrap</p>