• RSS

Statistics

  • Entries (3)
  • Comments (0)

Categories

Inka in Action part II: An Element Is Born 

Friday, June 13, 2008 2:41:28 PM

(continued from the previous post)

The next thing I needed is to display a group header. Remember that I grouped my records by a Boolean value, so that I had two groups. The IGrouping interface has the Key property, which is exactly the Boolean value I need. However, I don't want to place True or False in the header, I need "Materials" and "Work" instead.

I decided that it's time to create a custom element. It's called TrueFalseElement, and it's got two properties, TrueValue and FalseValue, which is what it displays when the underlying data is True or False (true or false in C#:). It won't check whether the data is Boolean.

The easiest (and recommended) way to create a text-based data-aware element is to inherit from Inka.Elements.DataElement and override the GetValue method:

  100     Protected Overrides Function GetValue() As String

  101         Dim value As Boolean = CBool(Me.DataObject)

  102         Return If(value, Me.TrueValue, Me.FalseValue)

  103     End Function

I'm using it like this:

matSection.AddElement(New TrueFalseElement With _

{.TrueValue = "Materials", .FalseValue = "Work", _

.Position = New Inka.Core.Utils.Shift(10, 5), .FontSize = 14})

You can see that creating a custom element is extremely easy: you override the GetValue method and return the desired value based on the DataObject property. You can also see that writing a test for it is also extremely easy: you don't need to set up any dependencies, since the element is totally idependent from other objects.

 

Copyright 2008 Sm-Art
1 + 5 =  

Site Map | Printable View | © 2008 - 2010 Your Company Name

Powered by mojoPortal | HTML 5 | CSS | Design by styleshout