Calculated fields

Posted by jmgawlik on 05-Aug-2009 09:45

I was wondering if there is a way to create a calculated field (if this is the right term) of sorts on the .Net side. I was thinking about the older ABL gui and how you can create a calculated field that could contain, among other things, the concatenation of two fields. The reason I ask, is that, I have a dataset that I am using as my source and I would like to be able to show two values in my combobox's display member. I would really like to just use the plain old MS version of the control to keep it simpler and a little more light weight (the Infragistics version is wonderful but seems like overkill for what I need). I know I can add a new field to the binding source's schema and simply bind to it but, of course, there is no actual data there (ok, very obvious).

Does anyone know of a good method? Can I actually do it without having to alter my existing dataset definition?

All Replies

Posted by marko.rueterbories on 05-Aug-2009 10:03

Hey John,

if you wan't to manualy control what happens you could use the PositionChanged Event of the BindingSource. Just add the subscription to your CONSTRUCTOR.


THIS-OBJECT:bindingSource1:PositionChanged:Subscribe (PositionChangedHandler).

And add the following Method to your class to handle the event.

METHOD PUBLIC VOID PositionChangedHandler (sender AS System.Object, e AS System.EventArgs):

        

    DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.

        

    hBuffer = DATASET dsOrder:GET-BUFFER-HANDLE ("ttOrder").

        

    MESSAGE hBuffer::Ordernum SKIP

            hBuffer::CustNum

        VIEW-AS ALERT-BOX.

END METHOD.

Instead of showing a message you can add the calculated Value to a Control of your choice.

Greets,

Marko

Posted by Peter Judge on 05-Aug-2009 10:04

I was wondering if there is a way to create a calculated field (if this is the right term) of sorts on the .Net side. I was thinking about the older ABL gui and how you can create a calculated field that could contain, among other things, the concatenation of two fields. The reason I ask, is that, I have a dataset that I am using as my source and I would like to be able to show two values in my combobox's display member. I would really like to just use the plain old MS version of the control to keep it simpler and a little more light weight (the Infragistics version is wonderful but seems like overkill for what I need). I know I can add a new field to the binding source's schema and simply bind to it but, of course, there is no actual data there (ok, very obvious)

The Microsoft DataGridView allows you to add unbound columns (ie calculated fields). It doesn't look like the MS combobox allows this: you're limited to bound or unbound.

I know I can add a new field to the binding source's schema and simply bind to it but, of course, there is no actual data there (ok, very obvious).

You might be able 'populate' it via the binding source's PositionChanged by setting the InputValue property to whatever you want. I'm not sure how or if this would work in the case of a 'scrolling' view (aka browse or grid), or even if it would work for non-root tables. But the binding source isn't really meant to hold data - it's more of a liason between the data and the UI controls (IMO).

I would suggest adding the field to the dataset and populating it when the dataset is populated. This way you can reuse that calculated field data wherever you need to, regardless of UI.

-- peter

Posted by jmgawlik on 05-Aug-2009 10:35

Thanks, that's about what I figured but I didn't think it would hurt to ask. I will probably just add the field to the dataset defintion. You're right, might as well have the option to reuse it else where.

Thanks again.

This thread is closed