vendredi 19 janvier 2018

Iteration of checkboxes to pdf c# class

so i had some wonderful help with the previous iteration of this that worked great!

i used the code

foreach (var checkbox in this.Controls.OfType<CheckBox>())
        {
            pdfFormFields.SetField(checkbox.Name, checkbox.Checked ? "Yes" : "No");
        }

and it worked great now ive been told to use a class to make it more universtal my class is

public class Entries
{
    public string SerialNumber;
    public string HeadType;
    public string TestedWithHandle;
    public string TestedWithCal;
    public string HardwareID;
    public string LaserClass;
    public string LaserWave;
    public string PWRatAperture;
    public string PWRat100mm;
    public string FilterType;
    public string Distance;
    public string ColourMB;
    public string ColourITTCB;
    public string ColourLRB;
    public string ColourW;
    public bool CheckBox1 { get; set; }
    public bool CheckBox2 { get; set; }
    public bool CheckBox3 { get; set; }
    public bool CheckBox4 { get; set; }
    public bool CheckBox5 { get; set; }
    public bool CheckBox6 { get; set; }
    public bool CheckBox7 { get; set; }
    public bool CheckBox8 { get; set; }
    public bool CheckBox9 { get; set; }
}

I need a foreach statement like the above but to set the info to the data in class something like this, however i get a identifier expected error.

foreach (var checkbox in this.Controls.OfType<CheckBox>())
        {
            Data.(checkbox.Name, checkbox.Checked ? "Yes" : "No");
        }

Help is appreciated, help with an explanation of how the code work is greatly appreciated!

sorry in advance, Im a hardware guy!




Aucun commentaire:

Enregistrer un commentaire