简体   繁体   English

在控件中获取验证错误消息

[英]Get Validation error messages in controls

I am using C# to build a windows form with DevExpress.我正在使用 C# 使用 DevExpress 构建 windows 表单。 In the windows form I have DXValidationProvider and DXErrorProvider to show error message for invalid cases.在 windows 表单中,我有 DXValidationProvider 和 DXErrorProvider 来显示无效案例的错误消息。 We try to use localization for error messages.我们尝试对错误消息使用本地化。 My question, how to check if the windows form has DXValidationProvider and how to check which contorls are defined in the DXValidationProvider.我的问题,如何检查 windows 表单是否具有 DXValidationProvider 以及如何检查 DXValidationProvider 中定义了哪些控制。 We tried to use the following code我们尝试使用以下代码

foreach (Control item in Controls)
{
    if (item is DXValidationProvider)
    {
        ....
    }
}

We got warning as shown in the below picture我们收到如下图所示的警告

在此处输入图像描述

DXValidationProvider is a Component and will not appear in Controls collection. DXValidationProvider是一个组件,不会出现在Controls集合中。

If you have added the component through designer, then there should be a components member in your form.如果您通过设计器添加了组件,那么您的表单中应该有一个components成员。 You can use it like this:你可以像这样使用它:

var provider = components.Components.OfType<DXValidationProvider>().FirstOrDefault();
if(provider != null)
{
    //do something ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM