Ticket Q256110
Visible to All Users

Validate Field against different Field

created 15 years ago

I have 2 different fields in a XtraGrid: 1 is bound to a LookupEdit, the second field ist a normal textual field. I implemented a Validation for Field #2 in the GridView_ValidatingEditor. The Validation checks Field #1 and depending on #1 value the Value für #2 must be a negative or a positive number.
The Validations works pretty good - unless I change the value of #1.
So actually I'm stuck in the gridview_CellValueChanged Event. I detect changes of Field #1 and all I need to to is revalidate Field #2.
I don't want to copy the validation itself, I'm searching a solution for triggering a manual validation of Field #2.
Any suggestions?

Show previous comments (2)
Anatol (DevExpress) 15 years ago

    Hello Sven,
    The issue occurs because the editor of the first column is not hidden when the ShowEditor method is called. As a result, this editor is validated. To resolve the problem, call the ColumnView.HideEditor method before changing focus, as shown below:

    C#
    private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (gridView1.FocusedColumn == colField1) { gridView1.HideEditor(); gridView1.FocusedColumn = colField2; gridView1.ShowEditor(); gridView1.ActiveEditor.IsModified = true; gridView1.ValidateEditor(); } }

    I also recommend that you handle the ValidateRow event when you have such fields dependences.
    Please let me know if you need any further help.
    Thanks,
    Anatol

      Thanks for your Reply, but it didn't work for me. I have the following Code in the CellValueChanged-Event:
           if (e.Column == coltypeid)
                  {
                      //validate ?!
                      gridView1.HideEditor();
                      gridView1.FocusedColumn = colcount;
                      gridView1.ShowEditor();
                      gridView1.ActiveEditor.IsModified = true;
          ** gridView1.ValidateEditor();
                  }
      I still got the evExpress.Utils.HideException at the marked line.

      Anatol (DevExpress) 15 years ago

        Hello Sven,
        You are right, this solution isn't good, since the first message, shown in the error tooltip, is incorrect. I've consulted with our developers, and they said that XtraGrid doesn't support such kind of validation at the cells level. This scenario should be implemented using row validation, via the ValidateRow event. I've created a sample project, demonstrating how to accomplish this task. Please let me know whether the result meets your needs.
        Thanks,
        Anatol

        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.