Page 1 of 1
for loop i++ for variable
Posted: Tue Sep 07, 2021 2:15 pm
by tognit
Hello
I would like to use the index from a for loop for dynamic variables.
how can you add the index value (i) to a name of the variable?
instead of ....
Code: Select all
selectArt01.Visible = true;
selectArt02.Visible = true;
selectArt03.Visible = true;
selectArt04.Visible = true;
selectArt05.Visible = true;
perhaps ....?
Code: Select all
for (int i = 1; i < 5; i++)
selectArt + (i).Visible = true;
selectArt01 is a combobox in a form.
best regards
steven
Re: for loop i++ for variable
Posted: Tue Sep 07, 2021 9:07 pm
by Lech Kulikowski
Hello,
Please check the following code:
Code: Select all
foreach (var comp in Form1.Components)
{
if (comp is Stimulsoft.Report.Dialogs.StiComboBoxControl)
{
if // check necessary name
((Stimulsoft.Report.Dialogs.StiComboBoxControl)comp).Enabled = false;
}
}
Thank you.
Re: for loop i++ for variable
Posted: Wed Sep 08, 2021 5:26 am
by tognit
hello Lech Kulikowski,
thank you for your answer.
I forgot to write that the number of fields is entered dynamically in the for loop.
Code: Select all
for (int i = 1; i < nudLotFields; i++)
selectArt + (i).Visible = true;
The variable "nudLotFields" is selected in advance using a select field (1-10).
The fields "selectArt01, selectArt02, etc." are not all visible and would be shown according to the selection "nudLotFields".
if I do it like that, it works, but unfortunately not dynamically
Code: Select all
if (nudMengeGeraete.Value >= 2)
selectArt02.Visible = true;
Re: for loop i++ for variable
Posted: Wed Sep 08, 2021 8:15 am
by Lech Kulikowski
Hello,
Please send us a sample report with test data that reproduces the issue for analysis.
Thank you.
Re: for loop i++ for variable
Posted: Thu Sep 09, 2021 9:29 am
by tognit
here is the file
- Test.mrt
- (160.51 KiB) Downloaded 168 times
Re: for loop i++ for variable
Posted: Fri Sep 10, 2021 1:19 pm
by Lech Kulikowski
Hello,
Please check the following code:
Code: Select all
int nameIndex = 1;
foreach (var comp in Form1.Components)
{
if (comp is Stimulsoft.Report.Dialogs.StiComboBoxControl)
{
if (((Stimulsoft.Report.Dialogs.StiComboBoxControl)comp).Name == "selectArt0"+nameIndex.ToString())
((Stimulsoft.Report.Dialogs.StiComboBoxControl)comp).Enabled = false;
nameIndex++;
}
}