locked
Variables a form available in another form RRS feed

  • Question

  • Good afternoon ladies and gentlemen.

    I would like to help in a matter aki ... I'm working on an application for windows mobile. In it I have a datagrid with the products. This grid is powered by a List. So the products I have in the system are in the List <Produtos> lstProdutos.

    I had to pass the contents of this list to another form but I can not. I tried as below but failed.

    List<Produto> lstProdutos = new List<Produto>();

    (here is the code that add products to list)

    / / create a new form to view the product data

    fVProduto fVProd = new fVProduto();
    fVProd.passControl = new fVProduto.PassControl(enviarDadosForm);
    fVProd.Show();


     

    private void enviarDadosForm(object sender)
    {
      lstProdutos = ((List<Produto>)sender);
    }

     

    In fVProduto () I have so. 
     

    public partial class fVProduto : Form
    {
       List<Produto> produtos = new List<Produto>();
       public delegate void PassControl(object sender);
       public PassControl passControl;

       public fVProduto()
       {
           InitializeComponent();
       }

     


     

       private void fVProduto_Load(object sender, EventArgs e)
       {
          int cont;
          if (passControl != null)
          {
             passControl(produtos);
             cont = produtos.Count;
          }
       }
    }

    What's been going on and that he is not going to list a form to another. Am I doing this right?

    I thank you if someone can help me.

    Regards,
    Fabio A. Pszepiura

    Saturday, February 27, 2010 6:18 PM

Answers

  • Hi,

    You may want to consider using a Manager class, this would be a singleton class which contains the List which you can then reference, via a static instance property, the List from both your forms.

    Hope this helps.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    • Marked as answer by warrentang Tuesday, March 2, 2010 3:40 AM
    Sunday, February 28, 2010 8:50 AM