so i had some wonderful help with the previous iteration of this that worked great!
I have tried modifying my code with the info at Get property value from string using reflection in C#
but either i am getting it wrong or my class is setup in a way as to not work with that method.
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
{
///Some other Values
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!
EDIT
So solved majority of the issues thanks to @Furkan Kambay managed to get check-boxes into and out of class but for some reason the check-boxes on the PDF will not set to the same state?
Longer explanation, class is set up form works fine all combo boxes and text fields when called pdfFormFileds("Textx", Entries.ColourW);
work fine however the PDF check boxes do not change state when using the code, i am using iTextSharp library
foreach (var box in Entries.CheckBoxes)
{
pdfFormFields.SetField(box.Key, box.Value ? "Yes" : "No");
}
Setup for PDF
string pdfTemplate = @"C:\Testing Templates\Pre V-Change Head Test Certificate Template.pdf";
string newFile = @"c:\temp\PDF\" + Entries.SerialNumber + " " + Entries.TestedWithCal + " Pre V-Change Head Test Certificate.pdf";
string Created;
PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;