Ticket Q263111
Visible to All Users
Duplicate

Highlight required field in detailview

created 15 years ago

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

Answers

created 15 years ago (modified 3 years ago)

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
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

    Show previous comments (4)
    Anatol (DevExpress) 11 years ago

      I have added a C# example to the initial answer. Hope you will find it helpful.

      MB MB
      Michael Bogaerts 10 years ago

        Is there a similar sample available for Win?

        Anatol (DevExpress) 10 years ago

          There is a similar event in WinForms - WinLayoutManager.ItemCreated. Handle it in the same manner as shown in the example and customize layout items of the required properties.
          In addition, we have an example of how to show error icons near required properties - Validation - How to highlight invalid properties when the View is shown.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.