TableCell Value Set on Grid with special column editors

Jul 21, 2009 at 11:14 PM

Hi -

Recently, I've been working on a set of classes to make white work with the open source grid, SourceGrid. I came across an issue when I tried to use white and my SourceGrid code to write a functional test around a grid that has columns for not only strings, but also DateTime, Decimals, etc. After some research into this I found the issue to be part of the setter for Value in TableCell. In the current source I have it looks like this:

 

            set
            {
                actionListener.ActionPerforming(this);
ValuePattern valuePattern = (ValuePattern) Pattern(ValuePattern.Pattern);
if (value is string)
{
Click();
valuePattern.SetValue(string.Empty);
keyboard.Send((string) value, actionListener);
keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.TAB);
}
else { if (!Value.Equals(value.ToString()))
{
Click();
valuePattern.SetValue(value.ToString());
}
}
}

 

The bold line is where I saw the problem. When we set the value of a cell that is restricted to decimal, this line ends up throwing an exception, due to not being able to set the value of a SourceGrid decimal editor to a string.

 

My solution:

Currently, instead of reference a white Core.dll, I've had to move white source into my project and changed the above code to like like the following:

 

            set
            {
                actionListener.ActionPerforming(this);
ValuePattern valuePattern = (ValuePattern) Pattern(ValuePattern.Pattern);
if (value is string)
{
Click();
if (string.IsNullOrEmpty((string)value))
valuePattern.SetValue(string.Empty);
keyboard.Send((string) value, actionListener);
keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.TAB);
}
else { if (!Value.Equals(value.ToString()))
{
Click();
valuePattern.SetValue(value.ToString());
}
}
}

 

I ran the white unit test and this change does not cause any of them to break. I'm curious to know if anyone else has: 1) either ran into a similar problem? and/or 2) has a better solution to my problem? I'd like to not have a project dependency on white and simply reference the latest dlls that are release, especially for such a small change.