Example T553576
Visible to All Users

Reporting for WinForms - Query Builder

This example shows how you can invoke the Query Builder in a WinForms application.

Query Builder in a WinForms application

Click the Run Query Builder button on the form to invoke the Query Builder. After you add a new query and close the Query Builder window, click Fill to populate the Grid Control with data from the query.

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Form1.cs(vb)
C#
using DevExpress.DataAccess.Sql; using DevExpress.DataAccess.UI.Sql; using DevExpress.XtraEditors; using System; namespace StandaloneQueryBuilderSample { public partial class Form1 : XtraForm { public Form1() { InitializeComponent(); sqlDataSource1.Queries.Clear(); } void runQBButton_Click(object sender, EventArgs e) { if(sqlDataSource1.Queries.Count == 0) { sqlDataSource1.AddQueryWithQueryBuilder(new QueryBuilderEditQueryContext(), CreateQueryBuilderRunner); } else sqlDataSource1.Queries[0].EditQueryWithQueryBuilder(new QueryBuilderEditQueryContext(), CreateQueryBuilderRunner); } QueryBuilderRunner CreateQueryBuilderRunner(DBSchema dbSchema, SqlDataConnection sqlDataConnection, QueryBuilderEditQueryContext context) { return cbHidePreview.Checked ? new NoPreviewQueryBuilderRunner(dbSchema, sqlDataConnection, context) : new QueryBuilderRunner(dbSchema, sqlDataConnection, context); } void fillButton_Click(object sender, EventArgs e) { gridControl1.DataSource = null; gridControl1.DataMember = null; gridView1.Columns.Clear(); sqlDataSource1.Fill(); gridControl1.DataSource = sqlDataSource1; gridControl1.DataMember = sqlDataSource1.Queries[0].Name; } } }
NoPreviewQueryBuilderRunner.cs(vb)
C#
using DevExpress.Data; using DevExpress.DataAccess.Native.Sql.QueryBuilder; using DevExpress.DataAccess.Sql; using DevExpress.DataAccess.UI.Native.Sql.QueryBuilder; using DevExpress.DataAccess.UI.Sql; using DevExpress.DataAccess.UI.Wizard.Services; using DevExpress.DataAccess.Wizard.Services; using DevExpress.LookAndFeel; using System; using System.Windows.Forms; namespace StandaloneQueryBuilderSample { public class NoPreviewQueryBuilderRunner : QueryBuilderRunner { class NoPreviewQueryBuilderView : QueryBuilderView { public NoPreviewQueryBuilderView(IQueryBuilderViewModel viewModel, IWin32Window owner, UserLookAndFeel lookAndFeel, IParameterService parameterService, IServiceProvider propertyGridServices, bool noCustomSql, bool light, IDisplayNameProvider displayNameProvider, bool noDiagram, bool legacyExpressionEditor, IExceptionHandler loaderExceptionHandler, IRepositoryItemsProvider repositoryItemsProvider) : base(viewModel, owner, lookAndFeel, parameterService, propertyGridServices, noCustomSql, light, displayNameProvider, noDiagram, legacyExpressionEditor, loaderExceptionHandler, repositoryItemsProvider) { this.layoutItemFilterButton.OptionsTableLayoutItem.ColumnIndex = 0; this.layoutItemParametersButton.OptionsTableLayoutItem.ColumnIndex = 1; this.layoutItemPreviewButton.OptionsTableLayoutItem.ColumnIndex = 2; this.layoutControl1.HideItem(this.layoutItemPreviewButton); } } public NoPreviewQueryBuilderRunner(DBSchema dbSchema, SqlDataConnection connection, QueryBuilderEditQueryContext context) : base(dbSchema, connection, context) { } protected override IQueryBuilderView CreateView(QueryBuilderViewModel queryBuilderViewModel) { return new NoPreviewQueryBuilderView(queryBuilderViewModel, Owner, LookAndFeel, ParameterService, PropertyGridServices, !EnableCustomSql, Light, DisplayNameProvider, NoDiagramControl, LegacyExpressionEditor, LoaderExceptionHandler, RepositoryItemsProvider); } } }

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.