Home › Forums › WinForms controls › Xceed Grid for WinForms › Use checkbox column with Oracle data.
-
AuthorPosts
-
#15548 |
Oracle database does not have a Boolean data type, so the dataset that is returned has a field that is a char data type with a value of ‘Y’ representing true and ‘N’ for false.
When I add the dataset to the grid it displays Y or N depending on the data and what I really need is a way to display this as a check box both in view and edit modes.
I could show you all the ways that I have come up with but the end results is the dataset (all records) gets changed on first view to the value of “true” or “false” or another senior is the column is marked with a red X.
There has to be an easy way to display an N/Y or T/F as a checkbox. Could anyone help me?
Thanks.
Imported from legacy forums. Posted by Albert (had 2378 views)
To resolve the issue, you override CheckBoxEditor and CheckBoxViewer. Here is some snippet of the code:
<code>
//In the Form1_Load of the Grid
gridControl1.Columns[ “CheckBoxColumn” ].CellEditorManager = new MyCheckBoxEditor( new WinCheckBox(), true, true );
gridControl1.Columns[ “CheckBoxColumn” ].CellViewerManager = new MyCheckBoxViewer( new WinCheckBox(), “Checked” );
//Load the data
this.shippersTableAdapter.Fill( “YourOracleDataBase” );//In MyCheckBoxEditor.cs
class MyCheckBoxEditor : CellEditorManager
{
public MyCheckBoxEditor( WinCheckBox template, bool inPlace, bool handleActivationClick )
: base( template, inPlace, handleActivationClick )
{
}protected override CreateControlMode CreateControlMode
{
get
{
return CreateControlMode.ClonedInstance;
}
}protected override System.Windows.Forms.Control CreateControl()
{
return ThemedControl.CloneControl( this.TemplateControl );
}protected override void SetControlValueCore( System.Windows.Forms.Control control, Cell cell )
{
( ( WinCheckBox )control).Checked = cell.Value.ToString() == “Y”;
}protected override object GetControlValueCore( System.Windows.Forms.Control control, Cell cell, Type returnDataType )
{
if( ( ( WinCheckBox )control ).Checked )
{
return “Y”;
}
else
{
return “N”;
}
}
}//In MyCheckBoxViewer.cs
class MyCheckBoxViewer : CellViewerManager
{
public MyCheckBoxViewer( WinCheckBox template, string propertyName )
: base( template, propertyName )
{
}protected override void SetControlValueCore( Xceed.Grid.Cell cell )
{
( ( WinCheckBox )this.Control ).Checked = cell.Value.ToString() == “Y”;
}
}
</code>Imported from legacy forums. Posted by CharlesB (had 279 views)
The code you provide worked great!
I have added a property to each class to set the true and false char externally and removed the hard code values of ‘Y’ and ‘N’. Now I can use this for both Y/N and T/F or 0/1.
Thanks!
Imported from legacy forums. Posted by Albert (had 3387 views)
-
AuthorPosts
- You must be logged in to reply to this topic.