Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • Hello,
                                    I need to highlight a set of required fields in detailview either by changing the color of the Caption or append a colored * to the caption.
                                    I started with the below sample but without any luck, can you providea working sample

                                     Private Sub View_ControlsCreated(ByVal sender As Object, ByVal e As EventArgs)
                                            Dim pInfoArray As PropertyInfo() = Me.View.ObjectTypeInfo.Type.GetProperties
                                            For i As Integer = 0 To pInfoArray.Length - 1
                                                Dim attr As RuleRequiredFieldAttribute = DirectCast(Attribute.GetCustomAttribute(pInfoArray(i), GetType(RuleRequiredFieldAttribute)), RuleRequiredFieldAttribute)
                                                If attr IsNot Nothing Then
                                                    DirectCast(DirectCast(View, DetailView).FindItem(pInfoArray(i).Name).Control, DevExpress.ExpressApp.Web.TableEx).BackColor = System.Drawing.Color.Red
                                                End If
                                            Next
                                        End Sub

                                You must  log in  or  register  to leave comments

                                1 Solution

                                0

                                Hello Pete,

                                Can you please provide me with your sample, because it's difficult to find what's wrong with your code without debugging it?
                                In any case, I see that you are trying to set the BackColor of the TableEx control. I don't think that this is the best way to do what you want.
                                It's better to process ASPxPropertyEdititor objects only (FindItem(name) as ASPxPropertyEditor) and then set the color of their Editor object.
                                Alternatively, you can use the approach I used in the How to highlight the focused editor in DetailView example, to process ASPxWebControl objects only (check out the HighlightFocusedLayoutItemDetailViewController class for more details).
                                I suggest you implement one of these approaches in your sample and attach it here if it doesn't work. Then I could help you further.

                                See Also:
                                http://documentation.devexpress.com/#Xaf/CustomDocument2729


                                Update:
                                You can modify your controller as follows:

                                [C#]...
                                    Protected Overloads Overrides Sub OnActivated()
                                        AddHandler View.ControlsCreated, AddressOf View_ControlsCreated
                                        AddHandler CType(CType(View, DetailView).LayoutManager, WebLayoutManager).ItemCreated, AddressOf WebLayoutManager_ItemCreated
                                    End Sub
                                    Private Sub WebLayoutManager_ItemCreated(ByVal sender As Object, ByVal e As ItemCreatedEventArgs)
                                        Dim editor As PropertyEditor = TryCast(e.DetailViewItem, PropertyEditor)
                                        If editor IsNot Nothing Then
                                            If editor.PropertyName = "Name1" Then
                                                Dim captionControl As Literal = DirectCast(DirectCast(e.TemplateContainer.Controls(0).Controls(0).Controls(0).Controls(0).Controls(0), System.Web.UI.Control), System.Web.UI.WebControls.Literal)
                                                captionControl.Text = "Some custom text1"
                                                TryCast(captionControl.Parent, WebControl).BackColor = Drawing.Color.Red
                                            End If
                                        End If
                                    End Sub
                                ...


                                Update 2:
                                Here is a C# example for version 14.1.6:

                                [C#]
                                public class ViewController1 : ObjectViewController<DetailView, Contact> { protected override void OnActivated() { base.OnActivated(); ((WebLayoutManager)View.LayoutManager).ItemCreated += ViewController1_ItemCreated; } void ViewController1_ItemCreated(object sender, ItemCreatedEventArgs e) { PropertyEditor editor = e.ViewItem as PropertyEditor; if (editor != null && editor.PropertyName == "FirstName") { ((LayoutItemTemplateContainer)e.TemplateContainer).Caption = "Some custom text1"; if (e.TemplateContainer.CaptionControl != null) { CustomizeCaptionControl(e.TemplateContainer.CaptionControl); } else { e.TemplateContainer.Load += TemplateContainer_Load; } } } void TemplateContainer_Load(object sender, EventArgs e) { LayoutItemTemplateContainerBase templateControler = (LayoutItemTemplateContainerBase)sender; templateControler.Load -= TemplateContainer_Load; CustomizeCaptionControl(templateControler.CaptionControl); } private void CustomizeCaptionControl(WebControl captionControl) { captionControl.BackColor = Color.Red; } protected override void OnDeactivated() { base.OnDeactivated(); ((WebLayoutManager)View.LayoutManager).ItemCreated -= ViewController1_ItemCreated; } }


                                Thanks,
                                Dennis

                                • De Poet 06.16.2010

                                  Hello Dennis
                                  Based on your response I have modified my code and still cannot change the color of the Caption and append astrisks (*).

                                • Helllo Pete,

                                  Thanks for your sample. I am working on it. Please bear with me.

                                  Thanks,
                                  Dennis

                                • Hi Pete,

                                  Thanks for your patience.
                                  You can modify your controller as follows:

                                  [C#]
                                  ... Protected Overloads Overrides Sub OnActivated() AddHandler View.ControlsCreated, AddressOf View_ControlsCreated AddHandler CType(CType(View, DetailView).LayoutManager, WebLayoutManager).ItemCreated, AddressOf WebLayoutManager_ItemCreated End Sub Private Sub WebLayoutManager_ItemCreated(ByVal sender As Object, ByVal e As ItemCreatedEventArgs) Dim editor As PropertyEditor = TryCast(e.DetailViewItem, PropertyEditor) If editor IsNot Nothing Then If editor.PropertyName = "Name1" Then Dim captionControl As Literal = DirectCast(DirectCast(e.TemplateContainer.Controls(0).Controls(0).Controls(0).Controls(0).Controls(0), System.Web.UI.Control), System.Web.UI.WebControls.Literal) captionControl.Text = "Some custom text1" TryCast(captionControl.Parent, WebControl).BackColor = Drawing.Color.Red End If End If End Sub ...
                                  Let me know if this suites you.

                                  Thanks,
                                  Dennis

                                • rushdan . 09.05.2014
                                  Hi Dennis,

                                  I need this feature in my project , could you convert the code to C# format for me ?

                                  Thanks

                                  From
                                  Rushdan
                                • I have added a C# example to the initial answer. Hope you will find it helpful.
                                You must  log in  or  register  to leave comments

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners