HomeActive Query Builder - HowTos and TroubleshootingHow-tos for WinForms .NET EditionHow to use ErrorProvider with the SQL Text Editor?

2.6. How to use ErrorProvider with the SQL Text Editor?


public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        queryBuilder1.SyntaxProvider = new MSSQLSyntaxProvider();

        queryBuilder1.MetadataContainer.LoadFromXMLFile("Northwind.xml");
    }

    private void plainTextSQLBuilder1_SQLUpdated(object sender, EventArgs e)
    {
        sqlTextEditor1.Text = plainTextSQLBuilder1.SQL;
    }

    private void sqlTextEditor1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
    {
        try
        {
            queryBuilder1.SQL = sqlTextEditor1.Text;
        }
        catch (SQLError exception)
        {
            e.Cancel = true;
            sqlTextEditor1.SetSelection(exception.ErrorPos.pos, exception.ErrorTokenValue.Length);
            errorProvider1.SetError(sqlTextEditor1, exception.Message);
        }
    }

    private void sqlTextEditor1_Validated(object sender, EventArgs e)
    {
        errorProvider1.SetError(sqlTextEditor1, "");
    }
}

This page was: Helpful | Not Helpful