for loop i++ for variable

Stimulsoft Reports.NET discussion
Post Reply
tognit
Posts: 3
Joined: Tue Sep 07, 2021 2:05 pm

for loop i++ for variable

Post 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
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: for loop i++ for variable

Post 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.
tognit
Posts: 3
Joined: Tue Sep 07, 2021 2:05 pm

Re: for loop i++ for variable

Post 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;
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: for loop i++ for variable

Post by Lech Kulikowski »

Hello,

Please send us a sample report with test data that reproduces the issue for analysis.

Thank you.
tognit
Posts: 3
Joined: Tue Sep 07, 2021 2:05 pm

Re: for loop i++ for variable

Post by tognit »

here is the file
Test.mrt
(160.51 KiB) Downloaded 112 times
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: for loop i++ for variable

Post 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++;
    }
}
Post Reply