What am I missing?

What am I missing?

Old forum URL: forums.lhotka.net/forums/t/1482.aspx


ajj3085 posted on Friday, October 13, 2006

Hi,

I implemented a SmartBoolean class.  One of the things it does is accept Yes / No as well as true and false as valid strings.

I added an implicit cast operator as well, from string to SmartBoolean.

The problem is when I'm editing through a grid (UltraGrid).  I type yes, tab off the cell and get an error saying it can't convert String to SmartBoolean.  I thought the casting would solve this problem, but it's not.

Any ideas why its not getting converted?

Thanks
Andy

hurcane replied on Friday, October 13, 2006

What property of SmartBoolean are you binding to? Our SmartData classes all have a Value property that matches the base data type. We typically bind to the Value property. We have a zero-filled integer class that is stopred as a string in the database. Some forms treat it as an integer and others treat it as a string. Value is type Integer, but StringValue is type string. We bind the UI to the appropriate property.

ajj3085 replied on Monday, October 16, 2006

I was exposing SmartBoolean itself.

I've almost got it completed using this code in the forms constructor:

            ValueList taxableValues;

            taxableValues =
                ItemsGrid.DisplayLayout.ValueLists.Add( "TaxableValueList" );
            taxableValues.ValueListItems.Add( new SmartBoolean( true ), "Yes" );
            taxableValues.ValueListItems.Add( new SmartBoolean( false ), "No" );
            ItemsGrid.DisplayLayout.Bands[
                0 ].Columns[ "Taxable" ].ValueList = taxableValues;

SonOfPirate replied on Monday, October 16, 2006

You may want to look at the source code for the UltraGrid and see what basis it uses for the conversion - if you can.  In other cases, where I have dug into an Infragistics control to see how it is doing things, I have found that they've relied on a TypeConverter for the class (defined using the System.Component.TypeConverter attribute).  If it doesn't find one it will use the default converter which, obviously, isn't going to know how to convert from a string to your SmartBoolean.

That's my guess.  You will most likely need to implement your own SmartBooleanConverter : TypeConverter and mark your class with the attribute to get the functionality you want with the UltraGrid.

Hope that helps.

 

ajj3085 replied on Monday, October 16, 2006

Pirate, thanks.

I didn't think about implementing a type converted, although I did implement the IConvertable interface.. which obviously didn't work..  I'll give that a shot.

Andy

Copyright (c) Marimer LLC