Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Creating an array of Fields
    primarykey
    data
    text
    <p>Hey! I want to create an array of fields. however my code return an error of the following: Field 'WindowsFormsApplication1.Form1.fieldArray' is never assigned to, and will always have its default value null. </p> <p>any suggestion to how I can solve this error?</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { private Field[] fieldArray; private Field f; public Form1() { InitializeComponent(); } private void populateTree(string path, TreeNode tv1) { string[] dir = Directory.GetDirectories(path); foreach (string d in dir) { string entry = Path.GetFileName(d); TreeNode t = tv1.Nodes.Add("Folder", entry, 0); populateTree(d, t); } string[] files = Directory.GetFiles(path); foreach (string f in files) { string entry = Path.GetFileName(f); tv1.Nodes.Add(f, entry, 1); } } private void Form1_Load(object sender, EventArgs e) { //populate the tree TreeNode t = treeView1.Nodes.Add("Units"); populateTree(@"..\units\", t); f = new Field(); for (int i = 0; i &lt; 10; i++) { fieldArray[i] = new Field(); } fieldArray[1].label.AutoSize = true; fieldArray[1].label.Location = new System.Drawing.Point(323, 9); fieldArray[1].label.Name = "Programtittle"; fieldArray[1].label.Text = "UAI UnitDef Editor"; this.Controls.Add(fieldArray[1].label); int clabel = 36; //fieldArray[1].varName = new string[] { "unitName", "name", "description" }; //define labels //popluate label for (int i = 1; i &lt; fieldArray[i].varName.Length; i++) { fieldArray[i].label = new Label(); fieldArray[i].label.AutoSize = true; fieldArray[i].label.Location = new System.Drawing.Point(323, clabel); fieldArray[i].label.Name = "label"; this.Controls.Add(fieldArray[i].label); fieldArray[i].label.Text = fieldArray[i].varName[i]; clabel = clabel + 26; } //populate textbox int cbox = 33; for (int i = 0; i &lt; fieldArray[i].varName.Length; i++) { fieldArray[i].txtBox = new TextBox(); fieldArray[i].txtBox.Location = new System.Drawing.Point(380, cbox); fieldArray[i].txtBox.Name = "txtBox"; fieldArray[i].txtBox.Size = new System.Drawing.Size(100, 50); this.Controls.Add(fieldArray[i].txtBox); cbox = cbox + 26; } } private void populateLabelTxtBox(string path) { //f.txtBox.Multiline = true; //added for testing purpose; //read,split file string text = System.IO.File.ReadAllText(path); char[] delimiters = new char[] { '{', '=', ';', '}' }; string[] parts = text.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i &lt; parts.Length; i++) { fieldArray[i].txtBox.Text = parts[i]; } } private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { if (treeView1.SelectedNode.Name != "Folder") { string text = System.IO.File.ReadAllText(treeView1.SelectedNode.Name); //f.txtBox.Text = text; populateLabelTxtBox(treeView1.SelectedNode.Name); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload