If you receive a bit field from database and want to show some text (Yes/No in this example), instead of checkboxes here is the solution. First you need a class that implements the
Infragistics.Win.IEditorDataFilter interface. Here is my implementation:
using System;
using System.Windows.Forms;
using Infragistics.Win;
namespace dbMotion.DAT {
internal class GridCheckBoxDataFilter:IEditorDataFilter {
#region IEditorDataFilter Members
object IEditorDataFilter.Convert(EditorDataFilterConvertArgs args) {
switch (args.Direction) {
case ConversionDirection.EditorToOwner:
args.Handled = true;
args.IsValid = true;
CheckState state = (CheckState) args.Value;
switch (state) {
case CheckState.Checked:
return "Yes";
case CheckState.Unchecked:return "No";
case CheckState.Indeterminate:return string.Empty;
} break;
case ConversionDirection.OwnerToEditor:args.Handled = true;
args.IsValid = true;
return args.Value.ToString() == bool.TrueString ? "Yes" : "No";
case ConversionDirection.DisplayToEditor:args.Handled = true;
args.IsValid = true;
return args.Value.ToString() == "Yes";
case ConversionDirection.EditorToDisplay:args.Handled = true;
args.IsValid = true;
return args.Value;
} throw new Exception("Invalid value passed into GridChecBoxDataFilter.Convert()");
}
#endregion
}
}
And after this add the following code to the "InitializeLayout" event of your UltraWinGrid:
private void Grid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
e.Layout.Bands[0].Columns["Col1"].Editor = new EditorWithText();
e.Layout.Bands[0].Columns["Col1"].Style = ColumnStyle.FormattedText;
e.Layout.Bands[0].Columns["Col1"].Editor.DataFilter = new GridCheckBoxDataFilter();
}
}