I know it has been years and this question never got a response, but I ran into this same issue and discovered a solution. So hopefully this helps anyone else who stumbles across this post.
For this solution, I was using PDFsharp v1.50.4589-beta4.
To figure this out, I used Adobe Acrobat to create a simple radio button group called "Radio1" with four buttons each named "Choice1", "Choice2", "Choice3", and "Choice4". I selected the "Choice1" button so that the radio field would have a value and then used breakpoints in Visual Studio to examine the AcroForm. I could see that the field "Radio1" was set to a value of "/Choice1" but I was unsure of the type that the value had and therefore unable to change it. So I ran the following code:
Code:
PdfDocument _document = PdfReader.Open("test.pdf", PdfDocumentOpenMode.Modify);
PdfAcroForm form = _document.AcroForm;
Console.WriteLine(form.Fields["Radio1"].Value.GetType().ToString());
This gave me an output of "PdfSharp.Pdf.PdfName". So I ran the following code to change the radio button to the third button, "Choice3":
Code:
PdfDocument _document = PdfReader.Open("test.pdf", PdfDocumentOpenMode.Modify);
PdfAcroForm form = _document.AcroForm;
//Select third button
form.Fields["Radio1"].Value = new PdfName("/Choice3");
//Ensure the new values are displayed
if (_document.AcroForm.Elements.ContainsKey("/NeedAppearances") == false)
_document.AcroForm.Elements.Add("/NeedAppearances", new PdfBoolean(true));
else
_document.AcroForm.Elements["/NeedAppearances"] = new PdfBoolean(true);
//Save as new document
_document.Save(@"testcopy.pdf");
And when I opened the "testcopy.pdf" in Acrobat, the radio button group did indeed have the third button selected.
If someone has a more intuitive way of accomplishing this, please let me know. For now, this is how I programmatically manipulate a radio button field.