Wyatt70

Wyatt70

  • NA
  • 4
  • 0

Set textbox value based on listbox selection

May 9 2005 10:04 AM
I have a windows form with a listbox and 16 textboxes. One of the textboxes is enabled by default, while the rest are disabled. The listbox is used to select the number of textboxes to be enabled. For example, if I select "5" in the listbox, then the first 5 textboxes should be enabled. I am attempting to use a for loop to do this, but I am stuck. The code is attached: Code for the listbox: this.cbxNoInst.Items.AddRange(new object[] { "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"}); this.cbxNoInst.Location = new System.Drawing.Point(152, 64); this.cbxNoInst.Name = "cbxNoInst"; this.cbxNoInst.Size = new System.Drawing.Size(40, 21); this.cbxNoInst.TabIndex = 47; this.cbxNoInst.Visible = false; this.cbxNoInst.SelectedIndexChanged += new System.EventHandler(this.cbxNoInst_SelectedIndexChanged); Code for one of the textboxes: this.txtInst2.Enabled = false; this.txtInst2.Location = new System.Drawing.Point(8, 88); this.txtInst2.Name = "txtInst2"; this.txtInst2.TabIndex = 54; this.txtInst2.Text = "Named Instance 2"; Code for the selected index changed event: private void cbxNoInst_SelectedIndexChanged(object sender, System.EventArgs e) { int numInstances = Convert.ToUInt16(instances); for (i=0;i

Answers (1)