#Region "Radio Functions" Private Function AddTableRowRadioList(ByVal labelText As [String], ByVal controlID As [String], _ ByVal radioOptions As String(), _ ByVal defaultValue As [String]) As TableRow Dim row As New TableRow() Dim labelCell As New TableCell() Dim controlCell As New TableCell() Dim label As New Label() Dim radioList As New RadioButtonList() Dim item As String label.Text = labelText label.CssClass = MyBase.LabelCssClass labelCell.Controls.Add(label) radioList.ID = controlID For Each item In radioOptions radioList.Items.Add(New ListItem(item, item)) Next radioList.SelectedValue = defaultValue radioList.RepeatDirection = RepeatDirection.Horizontal controlCell.Controls.Add(radioList) row.Cells.Add(labelCell) row.Cells.Add(controlCell) Return row End Function Private Function GetRadioSelection(ByVal radioListID As String) As String Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList) Return radioList.SelectedValue End Function Private Sub SetRadioSelection(ByVal radioListID As String, ByVal radioSelection As String) Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList) If radioList IsNot Nothing Then radioList.SelectedValue = radioSelection Else radioList.SelectedValue = radioList.Items.Item(0).Text End If End Sub Private Sub SetRadioListReadOnlyOption(ByVal radioListID As String, ByVal [readOnly] As Boolean) Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList) radioList.Enabled = Not [readOnly] End Sub #End Region
Public Shared MyRadioProperty As DependencyProperty = DependencyProperty.Register("MyRadio", GetType(System.String), GetType(MyActivity)) <Description("Please specify the target attribute")> _ <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _ <Browsable(True)> _ Public Property MyRadio() As String Get Return DirectCast(MyBase.GetValue(MyActivity.MyRadioProperty), [String]) End Get Set(ByVal value As String) MyBase.SetValue(MyActivity.MyRadioProperty, value) End Set End Property
Public Overrides Function GenerateActivityOnWorkflow(ByVal workflow As SequentialWorkflow) As Activity If Not Me.ValidateInputs() Then Return Nothing End If Dim MyActivity As New MyActivity() MyActivity.MyRadio = Me.GetRadioSelection("txtMyRadio") Return MyActivity End Function Public Overrides Sub LoadActivitySettings(ByVal activity As Activity) Dim MyActivity As MyActivity = TryCast(activity, MyActivity) If MyActivity IsNot Nothing Then Me.SetRadioSelection("txtMyRadio", MyActivity.MyRadio) End If End Sub Public Overrides Function PersistSettings() As ActivitySettingsPartData Dim data As New ActivitySettingsPartData() data("MyRadio") = Me.GetRadioSelection("txtMyRadio") Return data End Function Public Overrides Sub RestoreSettings(ByVal data As ActivitySettingsPartData) If data IsNot Nothing Then Me.SetRadioSelection("txtMyRadio", DirectCast(data("MyRadio"), String)) End If End Sub Public Overrides Sub SwitchMode(ByVal mode As ActivitySettingsPartMode) Dim [readOnly] As Boolean = (mode = ActivitySettingsPartMode.View) Me.SetRadioListReadOnlyOption("txtMyRadio", [readOnly]) End Sub Protected Overrides Sub CreateChildControls() Dim controlLayoutTable As Table controlLayoutTable = New Table() controlLayoutTable.Width = Unit.Percentage(100.0) controlLayoutTable.BorderWidth = 0 controlLayoutTable.CellPadding = 2 ' The following lines add the RadioButtonList Dim radioOptions As String() = {"option1", "option2", "option3"} controlLayoutTable.Rows.Add(Me.AddTableRowRadioList("My Caption:", "txtLoggingLevel", loggingOptions, "Normal")) Me.Controls.Add(controlLayoutTable) MyBase.CreateChildControls() End Sub
Maheshkumar S Tiwari edited Revision 3. Comment: Added tags
Ed Price MSFT edited Revision 1. Comment: Updated the References section.
Ed Price - MSFT edited Revision 2. Comment: Added TOC and minor title edit.