In order to change the default property editor from which is DropdownList control to RadioGroup control, first you should add the following file to your project folders [i.e. RadioGroupEnumPropertyEditor.vb]
1: Imports System
2: Imports System.Collections.Generic
3: Imports DevExpress.ExpressApp.Web.Editors
4: Imports System.Web.UI.WebControls
5: Imports DevExpress.ExpressApp.Utils
6: Imports DevExpress.ExpressApp
7: Imports DevExpress.ExpressApp.Model
8: Imports DevExpress.Web.ASPxEditors
9:
10: Imports System.ComponentModel
11:
12: Imports DevExpress.Xpo
13: Imports DevExpress.Data.Filtering
14:
15: Imports DevExpress.Persistent.Base
16: Imports DevExpress.Persistent.BaseImpl
17: Imports DevExpress.Persistent.Validation
18:
19: Imports DevExpress.ExpressApp.Editors
20:
21: <PropertyEditor(GetType(RadioButton), "CustomComboEditor", False)> _
22: Public Class CheckboxEnumPropertyEditor
23: Inherits WebPropertyEditor
24:
25: Private enumDescriptor As EnumDescriptor
26: Private controlsHash As New Dictionary(Of ASPxRadioButton, Object)()
27:
28: Public Sub New(ByVal objectType As Type, ByVal info As IModelMemberViewItem)
29: MyBase.New(objectType, info)
30: Me.enumDescriptor = New EnumDescriptor(MemberInfo.MemberType)
31:
32: End Sub
33:
34: Protected Overrides Function CreateEditModeControlCore() As WebControl
35: Dim placeHolder As New Panel()
36: controlsHash.Clear()
37: For Each enumValue As Object In enumDescriptor.Values
38: Dim radioButton As New ASPxRadioButton()
39: radioButton.ID = "radioButton_" + enumValue.ToString()
40: controlsHash.Add(radioButton, enumValue)
41: radioButton.Text = enumDescriptor.GetCaption(enumValue)
42: 'radioButton.CheckedChanged += New EventHandler(radioButton_CheckedChanged)
43: AddHandler radioButton.CheckedChanged, AddressOf radioButton_CheckedChanged
44: radioButton.GroupName = PropertyName
45: placeHolder.Controls.Add(radioButton)
46:
47: Next
48: Return placeHolder
49: End Function
50:
51: Private Sub radioButton_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
52: EditValueChangedHandler(sender, e)
53: End Sub
54: Protected Overrides Function GetPropertyDisplayValue() As String
55: Return enumDescriptor.GetCaption(PropertyValue)
56: End Function
57: Protected Overrides Sub ReadEditModeValueCore()
58: Dim value As Object = PropertyValue
59: If value IsNot Nothing Then
60: For Each radioButton As ASPxRadioButton In Editor.Controls
61: radioButton.Checked = value.Equals(controlsHash(radioButton))
62: Next
63: End If
64: End Sub
65:
66: Protected Overrides Function GetControlValueCore() As Object
67: Dim result As Object = Nothing
68: For Each radioButton As ASPxRadioButton In Editor.Controls
69: If radioButton.Checked Then
70: result = controlsHash(radioButton)
71: Exit For
72: End If
73: Next
74: Return result
75: End Function
76: Public Overrides Sub BreakLinksToControl(ByVal unwireEventsOnly As Boolean)
77: If Editor IsNot Nothing Then
78: For Each radioButton As ASPxRadioButton In Editor.Controls
79: ' radioButton.CheckedChanged -= New EventHandler(radioButton_CheckedChanged)
80: AddHandler radioButton.CheckedChanged, AddressOf radioButton_CheckedChanged
81: Next
82: If Not unwireEventsOnly Then
83: controlsHash.Clear()
84: End If
85: End If
86: MyBase.BreakLinksToControl(unwireEventsOnly)
87: End Sub
88: Public Shadows ReadOnly Property Editor() As Panel
89: Get
90: Return DirectCast(MyBase.Editor, Panel)
91: End Get
92: End Property
93: End Class
Second, you should change default property editor for target item by editing file Model.DesignedDiffs.xafml under project YourProjectName.Web, then you add the following XML tags to it.
<?xml version="1.0" encoding="UTF-8"?> <Application> <BOModel> <Class Name="Q183035Sample.Module.SampleObject"> <Member Name="RadioButtonEnumProperty" PropertyEditorType="Q183035Sample.Module.Web.RadioButtonEnumPropertyEditor" /> </Class> </BOModel> </Application>
No comments:
Post a Comment