Create loop to change name of combo boxes

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am going thru the learning process with C# & .NET so I was wondering if anyone can help me out with this issue.
I have created a Windows Form which has 12 combo boxes (in rows of 3 numbered 1-12). On the Form_Load event I am trying to populate all the boxes with values obtained from the registry (previously set), please see sample below. At the moment it is written with the actual combo box names i.e. combobox1, combobox2 & combobox3 and does exactly what it should. However, I would like to wrap this in a loop that will run 4 times, changing the number of the Printer & each combo box accordingly. For example, on the 1st run we would have Printer1, combobox1, combobox2 & combobox3. The next run would then have Printer2, combobox4, combobox5 & combobox6...etc.
I am struggling to find a way to rename the comboboxes as they are not strings. Any help would be greatly appreciated.
Steve
private void Form1_Load(object sender, EventArgs e)
{
////for testing get the editor so we can write test strings to the command line
//Document doc =
// acadApp.DocumentManager.MdiActiveDocument;
//Editor ed = doc.Editor;
////////////////////////////////////////////////////////////////////////////
//Make the cancel button default
this.ActiveControl = button6;
//Get the plot device list & make a collection of the names
PlotSettingsValidator psv = PlotSettingsValidator.Current;
StringCollection devlist = psv.GetPlotDeviceList();
***START LOOP HERE***
//See if we have already reistered a device & if so set the combobox to that device
int printer = 1; //this is just me testing the following line...it should be set by the repeat loop
string regPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Ezcad\\EzQPlot\\Printer" + printer;
string name = (EzReg.EzRegGet.getRegentry(regPath, "Name").ToString());
string media = (EzReg.EzRegGet.getRegentry(regPath, "Media").ToString());
string style = (EzReg.EzRegGet.getRegentry(regPath, "Style").ToString());
if (devlist.Contains(name))
{
Ez_Combo_Add.EzComboList.setCombo(devlist, comboBox1);
this.comboBox1.SelectedIndex = devlist.IndexOf(name);
}
else
{
Ez_Combo_Add.EzComboList.setCombo(devlist, comboBox1);
this.comboBox1.SelectedIndex = 1;
}
//Get the plot settings to access the media
PlotSettings ps = new PlotSettings(true);
using (ps)
{
// We should refresh the lists, in case setting the device impacts the available media
psv.SetPlotConfigurationName(ps, name, null);
psv.RefreshLists(ps);
StringCollection medlist = psv.GetCanonicalMediaNameList(ps);
for (int i = 0; i < medlist.Count; i++)
{
string localMedia = (psv.GetLocaleMediaName(ps, medlist[i]));
comboBox2.Items.Add(localMedia);
if (localMedia == media)
{
string conName = medlist[i];
this.comboBox2.SelectedIndex = medlist.IndexOf(conName);
}
}
}
//Get style list
StringCollection styleList = psv.GetPlotStyleSheetList();
if (styleList.Contains(style))
{
Ez_Combo_Add.EzComboList.setCombo(styleList, comboBox3);
this.comboBox3.SelectedIndex = styleList.IndexOf(style);
}