{"id":1218,"date":"2011-01-04T19:10:27","date_gmt":"2011-01-04T19:10:27","guid":{"rendered":"https:\/\/www.wapshere.com\/missmiis\/?p=1218"},"modified":"2011-01-21T12:48:30","modified_gmt":"2011-01-21T12:48:30","slug":"adding-a-radio-control-to-a-fim-custom-workflow-ui","status":"publish","type":"post","link":"https:\/\/www.wapshere.com\/missmiis\/adding-a-radio-control-to-a-fim-custom-workflow-ui","title":{"rendered":"Adding a Radio Control to a FIM Custom Workflow UI"},"content":{"rendered":"<p>Following on from the <a href=\"https:\/\/www.wapshere.com\/missmiis\/adding-a-checkbox-to-a-fim-custom-workflow-ui\">last post<\/a> about adding a CheckBox, here&#8217;s how I added a RadioButtonList to a custom workflow UI.<\/p>\n<blockquote><p>Note: I have also uploaded a version of this to the Technet Wiki: <a href=\"http:\/\/social.technet.microsoft.com\/wiki\/contents\/articles\/how-to-add-a-radiobuttonlist-to-a-fim-custom-workflow-ui.aspx\">How to Add a RadioButtonList to a FIM Custom Workflow UI<br \/>\n<\/a><\/p><\/blockquote>\n<p><!--more--><br \/>\nHere I&#8217;m adding a control which allows me to set a Logging Level. I then use the value Me.LoggingLevel in my code to decide which messages to write to the event log.<\/p>\n<p><a href=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/01\/radio-01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1219\" title=\"radio 01\" src=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/01\/radio-01-300x26.jpg\" alt=\"\" width=\"300\" height=\"26\" srcset=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/01\/radio-01-300x26.jpg 300w, https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/01\/radio-01.jpg 425w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h3>Define the property in the Activity code<\/h3>\n<p>The radio control will return a string value so I need to define the property in the Activity code.<\/p>\n<div><\/div>\n<p><code><\/p>\n<pre>    '''\r\n    '''  Identifies the target attribute\r\n    '''\r\n    Public Shared LoggingLevelProperty As DependencyProperty = DependencyProperty.Register(\"LoggingLevel\", GetType(System.String), GetType(MyActivity))\r\n    &lt;Description(\"Please specify the target attribute\")&gt; _\r\n    &lt;DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)&gt; _\r\n    &lt;Browsable(True)&gt; _\r\n    Public Property LoggingLevel() As String\r\n        Get\r\n            Return DirectCast(MyBase.GetValue(MyActivity.LoggingLevelProperty), [String])\r\n        End Get\r\n        Set(ByVal value As String)\r\n            MyBase.SetValue(MyActivity.LoggingLevelProperty, value)\r\n        End Set\r\n    End Property<\/pre>\n<p>\u00c2\u00a0<\/p>\n<p><\/code><\/p>\n<h3>UI code functions<\/h3>\n<p>Add the following functions to your UI code:<\/p>\n<div><\/div>\n<p><code><\/p>\n<pre>#Region \"Radio Functions\"\r\n    Private Function AddTableRowRadioList(ByVal labelText As [String], ByVal controlID As [String], _\r\n                                          ByVal radioOptions As String(), _\r\n                                          ByVal defaultValue As [String]) As TableRow\r\n        Dim row As New TableRow()\r\n        Dim labelCell As New TableCell()\r\n        Dim controlCell As New TableCell()\r\n        Dim label As New Label()\r\n        Dim radioList As New RadioButtonList()\r\n        Dim item As String\r\n\r\n        label.Text = labelText\r\n        label.CssClass = MyBase.LabelCssClass\r\n        labelCell.Controls.Add(label)\r\n\r\n        radioList.ID = controlID\r\n        For Each item In radioOptions\r\n            radioList.Items.Add(New ListItem(item, item))\r\n        Next\r\n        radioList.SelectedValue = defaultValue\r\n        radioList.RepeatDirection = RepeatDirection.Horizontal\r\n        controlCell.Controls.Add(radioList)\r\n        row.Cells.Add(labelCell)\r\n        row.Cells.Add(controlCell)\r\n        Return row\r\n    End Function\r\n\r\n    Private Function GetRadioSelection(ByVal radioListID As String) As String\r\n        Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList)\r\n        Return radioList.SelectedValue\r\n    End Function\r\n\r\n    Private Sub SetRadioSelection(ByVal radioListID As String, ByVal radioSelection As String)\r\n        Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList)\r\n        If radioList IsNot Nothing Then\r\n            radioList.SelectedValue = radioSelection\r\n        Else\r\n            radioList.SelectedValue = radioList.Items.Item(0).Text\r\n        End If\r\n    End Sub\r\n\r\n    Private Sub SetRadioListReadOnlyOption(ByVal radioListID As String, ByVal [readOnly] As Boolean)\r\n        Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList)\r\n        radioList.Enabled = Not [readOnly]\r\n    End Sub\r\n\r\n    Protected Overrides Sub CreateChildControls()\r\n        Dim controlLayoutTable As Table\r\n        controlLayoutTable = New Table()\r\n\r\n        'Width is set to 100% of the control size\r\n        controlLayoutTable.Width = Unit.Percentage(100.0)\r\n        controlLayoutTable.BorderWidth = 0\r\n        controlLayoutTable.CellPadding = 2\r\n        ' The following lines add the Radio Control\r\n        Dim loggingOptions As String() = {\"Normal\", \"Verbose\"}\r\n        controlLayoutTable.Rows.Add(Me.AddTableRowRadioList(\"Logging Level:\", \"txtLoggingLevel\", loggingOptions, \"Normal\"))\r\n        Me.Controls.Add(controlLayoutTable)\r\n\r\n        MyBase.CreateChildControls()\r\n    End Sub\r\n\r\n#End Region<\/pre>\n<p>\u00c2\u00a0<\/p>\n<p><\/code><\/p>\n<h3>Modify the default methods of the UI code<\/h3>\n<p>Finally modify the default metods of the UI code to handle the value.<\/p>\n<div><\/div>\n<p><code><\/p>\n<pre>    Public Overrides Function GenerateActivityOnWorkflow(ByVal workflow As SequentialWorkflow) As Activity\r\n        If Not Me.ValidateInputs() Then\r\n            Return Nothing\r\n        End If\r\n        Dim MyActivity As New MyActivity()\r\n        MyActivity.LoggingLevel = Me.GetRadioSelection(\"txtLoggingLevel\")\r\n        Return MyActivity\r\n    End Function\r\n\r\n    Public Overrides Sub LoadActivitySettings(ByVal activity As Activity)\r\n        Dim MyActivity As MyActivity = TryCast(activity, MyActivity)\r\n        If MyActivity IsNot Nothing Then\r\n            Me.SetRadioSelection(\"txtLoggingLevel\", MyActivity.LoggingLevel)\r\n        End If\r\n    End Sub\r\n\r\n    Public Overrides Function PersistSettings() As ActivitySettingsPartData\r\n        Dim data As New ActivitySettingsPartData()\r\n        data(\"LoggingLevel\") = Me.GetRadioSelection(\"txtLoggingLevel\")\r\n        Return data\r\n    End Function\r\n\r\n    Public Overrides Sub RestoreSettings(ByVal data As ActivitySettingsPartData)\r\n        If data IsNot Nothing Then\r\n            Me.SetRadioSelection(\"txtLoggingLevel\", DirectCast(data(\"LoggingLevel\"), String))\r\n        End If\r\n    End Sub\r\n\r\n    Public Overrides Sub SwitchMode(ByVal mode As ActivitySettingsPartMode)\r\n        Dim [readOnly] As Boolean = (mode = ActivitySettingsPartMode.View)\r\n        Me.SetRadioListReadOnlyOption(\"txtLoggingLevel\", [readOnly])\r\n    End Sub<\/pre>\n<p>\u00c2\u00a0<\/p>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following on from the last post about adding a CheckBox, here&#8217;s how I added a RadioButtonList to a custom workflow UI. Note: I have also uploaded a version of this to the Technet Wiki: How to Add a RadioButtonList to a FIM Custom Workflow UI<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[42,30,45],"tags":[],"class_list":["post-1218","post","type-post","status-publish","format-standard","hentry","category-fim-2010","category-vbnet","category-workflow"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pkp1o-jE","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/comments?post=1218"}],"version-history":[{"count":5,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1218\/revisions"}],"predecessor-version":[{"id":1278,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1218\/revisions\/1278"}],"wp:attachment":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/media?parent=1218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/categories?post=1218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/tags?post=1218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}