arrays - C# Trouble instanciating controls -


i'm attempting make array of control in c# visual studio express doesn't cooperate. i'm getting message @ run time:

object reference not set instance of object.

the error occurs @ arrow below. how make work?

public partial class protocoltool : form {     // ... other stuff      // doesn't seem make instances expect     // class string_entry defined lower     public string_entry[] pt_entries = new string_entry[nb_entries];      // constructor class protocol tool     public protocoltool()     {         initializecomponent();          // tried make instances here still doesn't work         //pt_entries = new string_entry[nb_entries];          // add supposedly instanciated control in tablelayoutpanel         entriesguiadd();          // ... other stuff     }      private void entriesguiadd()     {         (int = 0; < nb_entries; i++)         {             // tried make instances here still doesn't work             //pt_entries[i].create();              // tried make instances here directly, still doesn't work 

-----------> pt_entries[i].textbox = new system.windows.forms.textbox(); pt_entries[i].send = new system.windows.forms.button();

            //tablelayoutpanel1.controls.add(pt_entries[i].textbox, 0, i);             //tablelayoutpanel1.controls.add(pt_entries[i].send, 1, i);         }     } } // end of protocoltool class  public class string_entry {     public textbox textbox;     public button send;     public int sequential_counter;      // constructor here doesn't work @      /*     ... put constructor here instead, still doesn't work     public void create()     {         console.writeline("creating entry");         // tried make instances here still doesn't work         textbox = new textbox();         send = new button();         send.click += new system.eventhandler(this.bsend_click);     }     */      // ... other functions  } 

you need initialize pt_entries[i] before can reference properties of it.

pt_entries[i] = new string_entry(); pt_entries[i].textbox = new system.windows.forms.textbox();  pt_entries[i].send = new system.windows.forms.button(); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -