We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Radio Buttons in Aspose.Cells

Hello,

I cannot get my radio buttons to set properly.

I create several group boxes in a worksheet and several radiobuttons within each group, then I group the shapes. But when I try to set ischecked to true only the last button on the worksheet is checked. It’s like aspose.cells doesn’t honor the grouping.
This is how I’m making my groups, which behave correctly in the resulting file (attached)


Private Function CreateRadioHbuttonsfromTags(ByVal workbook As Workbook) As Workbook
'This function creates Horizontal radio buttons for each cell that has a value like RadioH(datatable.datafield):item1text,item2text


Dim worksheet As Worksheet = workbook.Worksheets(0)
Dim groupcounter As Integer = 0
For Each worksheet In workbook.Worksheets


Do Until worksheet.Cells.FindStringContains(“RadioH:”, worksheet.Cells(0, 0)) Is Nothing

groupcounter = groupcounter + 1


Dim Targetcell As Aspose.Cells.Cell = worksheet.Cells.FindStringContains(“RadioH:”, worksheet.Cells(0, 0))
Dim strRadioItems() As String = Targetcell.StringValue.Replace(“RadioH:”, “”).Split(",")

Dim intNumItems As Integer = UBound(strRadioItems)
Dim intTotalWidth As Integer = 0
Dim x As Integer
Dim shapeobjects() As Aspose.Cells.Shape

For x = 0 To intNumItems

intTotalWidth = intTotalWidth + worksheet.Cells.GetColumnWidthPixel(Targetcell.Column + x)

Next x

Dim groupbox As Aspose.Cells.GroupBox = worksheet.Shapes.AddGroupBox(Targetcell.Row, 0, Targetcell.Column, 0, worksheet.Cells.GetRowHeightPixel(Targetcell.Row), intTotalWidth)
groupbox.LineFormat.IsVisible = False
groupbox.IsHidden = True

ReDim shapeobjects(0)
shapeobjects(0) = groupbox

Dim rad0 As Aspose.Cells.RadioButton
Dim WidthOffset As Int16 = 0

'Dim txt As Aspose.Cells.TextBox

For x = 1 To intNumItems + 1

’ this line centers
’ rad0 = worksheet.Shapes.AddRadioButton(Targetcell.Row, 0, Targetcell.Column + x - 1, (worksheet.Cells.GetColumnWidthPixel(Targetcell.Column + x - 1) / 2) - 10, worksheet.Cells.GetRowHeightPixel(Targetcell.Row), worksheet.Cells.GetColumnWidthPixel(Targetcell.Column + x - 1) / 2)


rad0 = worksheet.Shapes.AddRadioButton(Targetcell.Row, 0, Targetcell.Column + x - 1, WidthOffset, worksheet.Cells.GetRowHeightPixel(0), worksheet.Cells.GetColumnWidthPixel(Targetcell.Column + x - 1))

rad0.Text = strRadioItems(x - 1).Trim

rad0.Placement = PlacementType.MoveAndSize
rad0.Name = “rad” + Trim(rad0.Text.Replace("’", “”).Replace(" “, “_”)) + groupcounter.ToString
rad0.TextFrame.AutoSize = True



If rad0.Text.Length * 7.5 > rad0.Width Then
WidthOffset = WidthOffset + (rad0.Text.Length * 7.5) - rad0.Width + 10


End If



ReDim Preserve shapeobjects(x)
shapeobjects(x) = rad0
’ rad0 = Nothing
Next
groupbox.Width = groupbox.Width + (WidthOffset * 1.25) + 50

Dim group As Aspose.Cells.GroupShape = worksheet.Shapes.Group(shapeobjects)


’ group.GroupItems.Item(1).linkedcell = Trim(ColumnNames(Targetcell.Column + x)) & Trim(Targetcell.Row.ToString)
’ rad0.LinkedCell = ColumnNames(Targetcell.Column + x) & Targetcell.Row.ToString
shapeobjects = Nothing




Targetcell.PutValue(”")



Loop

Next



CreateRadioHbuttonsfromTags = workbook


End Function

But I can’t set these values.

If I try

Dim workbook As New Workbook

workbook.Open(“c:\tsttextboxes.xls”)

Dim worksheet As Worksheet = workbook.Worksheets(3)



Dim item As Object


For Each item In worksheet.Shapes

’ MsgBox(worksheet.Name & " " & item.GetType.ToString() & " " & item.Name)

If item.GetType.ToString() = “Aspose.Cells.RadioButton” Then

If item.Name Like “Yes” Then

'Dim rad As Aspose.Cells.RadioButton = item
item.IsChecked = True

’ MsgBox(item.ischecked.ToString)


End If
End If
Next
workbook.Save(“c:\tsttextboxes2.xls”)


This doesn’t work . Any ideas on how I can set the value of certain grouped radio boxes in an excel worksheet? I have been using the unliscened version, but we do have a licesnce

Thanks,

Ryan Mergen
rmergen@enterprisecommunity.org

Hi,

Which Aspose.Cells version you are using? Could you try the attached version, I tested your code with it and it works fine. All the radio buttons containing 'Yes' string as a part of their Names in the fourth sheet will be selected in the output excel file.

Thank you.



That solved the problem. Thanks for the quick turnaround!