windowsforms-116901-controls-and-libraries-gauges-examples-how-to-use-gauges-for-in-place-editing.md
DevExpress data-aware controls like Data Grid and Tree List allow your end-users to edit data using embedded editors from the Editors library. Since gauges are not part of the Editors library, in-place editing using gauges is not supported out-of-the-box. However, you can manually embed gauges into data cells by using the RepositoryItemAnyControl object. This example demonstrates how to do that.
Create a sample WinForms application and drop a Data Grid onto the main form.
Add a new class that will define your sample data.
Bind your Data Grid to this sample data. To do so, specify the Grid Control’s GridControl.DataSource property.
To visualize the “Severity” field, drop a Gauge Control onto the form. When you do so, the Preset Manager will pop up automatically. Apply the “ElectricLights” preset to create a state indicator gauge that displays red, yellow and green lights.
Resize your gauge as required and set its visibility (the Visible property) to false.
Add a method that will create a new RepositoryItemAnyControl with the required gauge control within and use this object as the in-place editor for the target grid column.
To replace the default combo box editor for the existing column, use the following code.
The steps above demonstrate the most simple scenario - gauges are used to replace default in-place editors for a column that is already populated. At the same time, cell values for this column contain integer enumerator values acceptable to your gauges.
If your in-place gauges should display custom values, you will need to process these values manually. For instance, in the example above, you could create a new unbound column with gauges instead of replacing the existing “Severity” column. For this scenario, repeat the first six steps from the sequence above and then do the following.
Create an unbound column and use the custom CreateGaugeEdit method to set this column’s in-place editor.
To supply your gauges with values, first create a separate class that implements required interfaces declared in the DevExpress.XtraGauges.Win.Base namespace. There are three of these interfaces:
Handle the ColumnView.CustomUnboundColumnData event. In this event handler, you need to retrieve the current record severity and pass it to a new instance of you custom SeverityGaugeEditValue class. By doing so, you will pass this severity value to a gauge.
Run the application to see the final result.
The code above makes use of the IValueProvider interface only. To see a more complex example with gauges that utilize all three I…Provider interfaces, explore the following demo: