private void DisplayParameters() { // build list of controls starting with lb_ and nud_ List <Control> listControl = new List <Control>(); foreach (Control ctrl in Controls) { if (ctrl.Name.StartsWith("nud_") || ctrl.Name.StartsWith("lb_")) { listControl.Add(ctrl); } } // remove these controls foreach (Control ctrl in listControl) { Controls.Remove(ctrl); } listControl.Clear(); // get selected combo item CompComboItem item = cbComponent.SelectedItem as CompComboItem; if (null == item) { return; } // get selected component parameters Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Dictionary <string, double> dict = Pic.DAL.SQLite.Component.GetParamDefaultValues(db, item.Guid); // create controls const int lblX = 10, nudX = 160, incY = 26; Size sizelb = new Size(150, 18), sizenud = new Size(70, 12); int posY = 10; int tabIndex = 0; foreach (KeyValuePair <string, double> param in dict) { Label lb = new Label(); lb.Name = "lb_" + param.Key; lb.Text = param.Key; lb.Size = sizelb; lb.Location = new System.Drawing.Point(lblX, posY); lb.TabIndex = ++tabIndex; Controls.Add(lb); NumericUpDown nud = new NumericUpDown(); nud.Name = "nud_" + param.Key; nud.Value = (decimal)param.Value; nud.Size = sizenud; nud.Location = new System.Drawing.Point(nudX, posY); nud.TabIndex = ++tabIndex; Controls.Add(nud); // increment Y posY += incY; } }
private void cbComponent_SelectedIndexChanged(object sender, EventArgs e) { // save parameters SaveParameters(); // get selected component guid CompComboItem item = cbComponent.SelectedItem as CompComboItem; if (null == item) { return; } // change guid _guid = item.Guid; // Update parameters UpdateParameters(); }