Separate radio button for table cell

I would like to add a radio button inside a cell each in a table! No grouping, only one separate radio button for every cell . How do I do this?

Hi,

Thanks for using our products.

As per your requirements, you need to create separate FormField of RadioButton type and create individual RadioButton and add it to RadioButtons collection of previously created form field and finally add the FormField to paragraphs collection of table cell. Please take a look over the following code snippet which I have used to accomplish this requirement. For your reference, I have also attached the PDF document that I have generated using Aspose.Pdf for .NET 5.2.0. In case it does not satisfy your requirements or you have any further query, please feel free to contact.

[C#]

//Instantiate the Pdf document and add a section to it
Pdf pdf1 = new Pdf();
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();
//Create a table, set its column widths and add it to paragraphs collection
//of the section
Table table1 = new Table();
//Set with column widths of the table
table1.ColumnWidths = "50 50 50";
//Set default cell border using BorderInfo object
table1.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.1F);
//Set table border using another customized BorderInfo object
table1.Border = new BorderInfo((int)BorderSide.All, 1F);
table1.ColumnWidths = "120 120 120";
sec1.Paragraphs.Add(table1);

//Add a row to the table
Row row1 = table1.Rows.Add();
//Add 1st cell to the row, set its padding and set the ID of the first paragraph
//in the cell to "text1"
Cell cell1 = row1.Cells.Add("item1");
cell1.Padding.Left = 30;
cell1.Paragraphs[0].ID = "text1";
//Add 2nd cell to the row, set its padding and set the ID of the first paragraph
//in the cell to "text2"
Cell cell2 = row1.Cells.Add("item2");
cell2.Padding.Left = 30;
cell2.Paragraphs[0].ID = "text2";
//Add 3rd cell to the row, set its padding and set the ID of the first paragraph
//in the cell to "text3"
Cell cell3 = row1.Cells.Add("item3");
cell3.Padding.Left = 30;
cell3.Paragraphs[0].ID = "text3";

//Create a form field of RadioButton type. Set its field name and button color.
//Then set the index of the radio button value to be checked
FormField radio = new FormField();
radio.FormFieldType = FormFieldType.RadioButton;
radio.FieldName = "ARadio";
radio.ButtonColor = System.Drawing.Color.FromName("Red");
//Create 1st radio button instance and add it to above created radio form field.
//Set its width and height. The position of the radio button is set to be
//relative to the paragraph. Link this radio button with the paragraph with ID
//equal to "text1".
Aspose.Pdf.RadioButton RadioButton1 = radio.RadioButtons.Add();
RadioButton1.ButtonHeight = 12;
RadioButton1.ButtonWidth = 12;
RadioButton1.PositioningType = PositioningType.ParagraphRelative;
RadioButton1.ReferenceParagraphID = "text1";
RadioButton1.Left = -20;
RadioButton1.Top = 0;

//Create a form field of RadioButton type. Set its field name and button color.
FormField radio2 = new FormField();
radio2.FormFieldType = FormFieldType.RadioButton;
radio2.FieldName = "ARadio2";
radio2.ButtonColor = System.Drawing.Color.FromName("Green");
//Create 2nd radio button instance and add it to above created radio form field.
//Set its width and height. The position of the radio button is set to be
//relative to the paragraph. Link this radio button with the paragraph with ID
//equal to "text2".
Aspose.Pdf.RadioButton RadioButton2 = radio2.RadioButtons.Add();
RadioButton2.ButtonHeight = 12;
RadioButton2.ButtonWidth = 12;
RadioButton2.PositioningType = PositioningType.ParagraphRelative;
RadioButton2.ReferenceParagraphID = "text2";
RadioButton2.Left = -20;
RadioButton2.Top = 0;

//Create a form field of RadioButton type. Set its field name and button color.
FormField radio3 = new FormField();
radio3.FormFieldType = FormFieldType.RadioButton;
radio3.FieldName = "ARadio3";
radio3.ButtonColor = System.Drawing.Color.FromName("Blue");
//Create 3rd radio button instance and add it to above created radio form field.
//Set its width and height. The position of the radio button is set to be
//relative to the paragraph. Link this radio button with the paragraph with ID
//equal to "text3".
Aspose.Pdf.RadioButton RadioButton3 = radio3.RadioButtons.Add();
RadioButton3.ButtonHeight = 12;
RadioButton3.ButtonWidth = 12;
RadioButton3.PositioningType = PositioningType.ParagraphRelative;
RadioButton3.ReferenceParagraphID = "text3";
RadioButton3.Left = -20;
RadioButton3.Top = 0;

//Add the radio form field to the paragraphs collection of the section
sec1.Paragraphs.Add(radio);
sec1.Paragraphs.Add(radio2);
sec1.Paragraphs.Add(radio3);
// save the resultant PDF document
pdf1.Save(@"d:/pdftest/RadioButton_InTableCell.pdf");

However, if you need to add three RadioButtons (each cell containing single RadioButton) and all the RadioButtons are grouped, please visit the following link for required information. Manipulating Form Fields