Cell Validation

Originally Posted 15 March 2017, 10:43 am EST

  • Originally Posted 15 March 2017, 10:43 am EST

    I'm using a FlexGrid, and have a couple of cell validation issues I can't work out.

    Invalid value selection
    In the ValidateEdit event, I can validate the value, and use e.Cancel if it's invalid. This works fine.
    However, this leaves the cursor at the position the user stopped typing.
    I find that I then try to type in a correct value, but this simply adds further characters to the value in the cell.
    Is it possible to highlight/select all the text in a cell if the validation fails?

    Set Value on validation fail
    Is it possible to set the value if the validation fails?
    For example, I have a FlexGrid with float (Single) values. The upper limit is 50.
    If the user enters 100, I want to show an error message using a MessageBox, and then set the value to the maximum value.
    This obviously mustn't happen in the ValidateEdit event, so where should it happen?

    Thanks
  • Reply

    Anyone?
  • Reply

    Hi,

    Below are the answers for your questions:
    1. In ValidateEdit event you can select all the text when validation fails after setting e.Cancel to true by getting the editor of the FlexGrid as TextBox and calling it's SelectAll method.
    private void c1FlexGrid1_ValidateEdit(object sender, ValidateEditEventArgs e)
    {
    if(e.Col == 1)
    {
    if(c1FlexGrid1[e.Row,e.Col].ToString() != "TEST")
    {
    e.Cancel = true;

    TextBox tb = (TextBox)c1FlexGrid1.Editor;
    tb.SelectAll();
    }
    }
    }

    2. To set the maximum value in a cell when user enters a higher value you need to use AfterEdit event of FlexGrid.
    private void c1FlexGrid1_AfterEdit(object sender, RowColEventArgs e)
    {
    if(e.Col == 2)
    {
    if(Convert.ToSingle(c1FlexGrid1[e.Row,e.Col]) > 50)
    {
    MessageBox.Show("Maximum Limit Is 50.");
    c1FlexGrid1[e.Row, e.Col] = 50;
    }
    }
    }


    Hope it helps.

    Thanks,
    Akshay
  • Marked as Answer

    Reply

    Thanks
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels