Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Bind a Gauge Control to a Data Source at Runtime

The following example shows how to bind a digital gauge’s DigitalGauge.Text property to a field in the NWind database using the traditional .NET binding mechanism.

In the example, the Text property is bound to a UnitPrice field in the Products table.

To learn about the data-binding mechanism, see MSDN.

using System.Data.OleDb;
using System.Windows.Forms;

// Create a connection object.
OleDbConnection connection = new OleDbConnection(
  "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\DATA\\NWIND.MDB");

// Create a data adapter.
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Products", connection);

// Create a BindingSource and populate it with data.
BindingSource bs = new BindingSource(new DataTable(), "");
adapter.Fill(bs.DataSource as DataTable);

// Bind the Text property to the UnitPrice field in the Products table.
digitalGauge1.DataBindings.Add("Text", bs, "UnitPrice");