Home - Forums-.NET - FlyGrid.Net (Windows Forms) - problem with inheriting BooleanColumn

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

problem with inheriting BooleanColumn
Link Posted: 14-Jul-2006 08:33
I am trying to inherit this column, so I can map the values Y and N to True and False.  Or any other arbitrary values to True and False.

I can override GetValue. This doesn't seem to help.

I can override GetCheckBoxState.  This helps get the checkbox in the initially correct state.

However, when I click the checkbox afterwards, it remains checked if it was already checked.

I believe I found the problem.

In the OnCellClick method of BooleanColumn, you have a call to SetValue that does this:
SetValue(node, !InternalGetBool(node));

This calls the private InternalGetBool property, which does the following in its get:

return Convert.ToBoolean(base.GetValue(node));

Shouldn't this be:

return Convert.ToBoolean(GetValue(node));

This way, I can override GetValue, and return the appropriate boolean based on Y or N.  Then, this all goes up the chain correctly.

As of now, my version of GetValue does not get called.  It calls the base class version, which expects a boolean, whereas the underlying data has a Y or N.

Shouldn't all the code in the grid call the methods directly, without going to the base class? This defeats the purpose of overrideable methods.

Unless I am missing something, but it seems like getting rid of the 'base' would solve the problem?
Link Posted: 14-Jul-2006 09:22
InternalGetBool translates a value provided to Checked/Unchecked states of checkbox displayed.
You can provide overriden GetCheckBoxState method to provide your own translation to more wide range of checkbox states - grayed checked, grayed unchecked and more (see the Grid Stylizing... sample for the ThreeStateColumn example).
All that you should do to translate Y or N to checkbox state is following:
[c#]
public class MyBooleanColumn : BooleanColumn
{
  //....
  
  //translate value from cell value
  protected override CheckBoxState GetCheckBoxState(NodeBase node)
  {
    return GetValue(node) == \"Y\" ? CheckBoxState.Checked : CheckBoxState.None;
  }

  //translate value to set to cell value
  public override void SetValue(NodeBase node, object value)
  {
     base.SetValue(node, value == true ? \"Y\" : \"N\");
  }
}
Link Posted: 17-Jul-2006 01:49
I tried running this code (translated into VB), and it doesn't work.  As I try to check/uncheck the checkbox, it doesn't work.  I think it is still the same issue as my original post.

As I said in my original post, I know I can override GetCheckBoxState.

Overriding GetCheckBoxState, SetValue and GetValue does not work, because of the implementation of GetInternalBool. I provided the exact source code that I believe is at fault.

Please provide a code snippet that works, if I am mistaken in why there is a bug with BooleanColumn.

Please reread my first post. It has the exact details of the problem with BooleanColumn

Thanks,
Marina
Link Posted: 17-Jul-2006 04:09

As of now, my version of GetValue does not get called. It calls the base class version, which expects a boolean, whereas the underlying data has a Y or N.

Shouldn't all the code in the grid call the methods directly, without going to the base class? This defeats the purpose of overrideable methods.


We've made some modifications to the BooleanColumn, with the nearest FlyGrid.Net update you can override following methods to improve BooleanColumn:
1. SwitchValue - to switch between values on mouse click or key press and set new value.
2. GetValue to translate values to display.
3. GetCheckBoxState - translate value to CheckBoxState.

We plan to publish this update tomorrow.