1

So I have this code:

 private void frmSell_Load(object sender, EventArgs e)
 {
      dgvProducts.DataSource = _data.AllProducts();
 }

Where _data.AllProducts() returns a List. The only problem is that line will only work when outside the _Load() event, for example, it will perfectly work when placed inside a button´s OnClick()

How can I load de products in the _Load event?

  • Maybe you forget to attach `frmSell_Load` to `Load` event of the form. – Reza Aghaei Feb 09 '17 at 19:46
  • 1
    Have you tried `dgvProducts.DataBind();` immediately after `dgvProducts.DataSource = _data.AllProducts();`? – Tumen_t Feb 09 '17 at 19:49
  • `dgvProducts.DataBind()` belongs to `WebForms`. The question is tagged with `WinForms`. – Reza Aghaei Feb 09 '17 at 19:50
  • Well other lines work inside the _Load event, like Button1.Text = "something" will change the text inside the button – Miguel Marzo Feb 09 '17 at 19:50
  • 2
    So you need to post a code to reproduce the problem, because currently based on your descriptions and comments we should just guess something which will be waste of time. – Reza Aghaei Feb 09 '17 at 19:51
  • Possible: https://msdn.microsoft.com/en-us/library/fbk67b6z(v=vs.110).aspx – Mokey Feb 09 '17 at 19:52
  • Sometimes, procedures don't work when called from the constructor. In that case, implement the FormActivate event and call the procedure in the first FormActivate. – Graffito Feb 09 '17 at 20:28
  • just place it under `InitializeComponent();` – active92 Feb 10 '17 at 00:48

0 Answers0