+1 800 256 3608 (toll-free in North America) or +49 7531 90 60 10| service@combit.com

Are older methods/events available in newer versions of LL using VB.Net for Unbound data?

We have numerous older programs being updated to VB.Net or C#.Net.
These programs generate data that is not bound to any data source and doesn’t lend itself well to do so. There are multiple arrays and variables that are not easily relatable as a data set.
Below is a snippet of code of how unbound data is passed to LL with our older programs.

LL automatically calls this routine to populate data used by report when design or print is evoked. My understanding is that these methods and events are still available but I am unable to figure out how to use them or the correct syntax.

Sub ListLabel_CmndDefineFields(ByVal nUserData As Long, ByVal bDummy As Long,_ pnProgressInPerc As Long, pbLastRecord As Long)

     ErrorCode = MainFrm.ListLabel.LlDefineFieldExt(“Field Name1”, FDatadbl(RecordIndex), LL_NUMERIC)

  If RecordIndex = LastRecord Then
     pbLastRecord = 1
     Index = 0
     RecordIndex = RecordIndex + 1
  End If                             

End Sub

Yes, for compatibility reason the event based data supply is still supported, albeit usage is discouraged because you’ll be missing a number of great features that way (no Designer preview, no hierarchies, drilldown, report parameters etc.). That said, you could go ahead like this:

Add a handler for the DefineFields event. You’ll get a deprecated warning on this one, for the reasons mentioned above.

using (ListLabel LL = new ListLabel())
    LL.DefineFields += LL_DefineFields;

The event handler itself could look like this (oversimplification intended :wink: ):

string[] _dataSource = new string[] { "A", "B", "C" };
int _currentRecordIndex = 0;

private void LL_DefineFields(object sender, DefineElementsEventArgs e)
    (sender as ListLabel).Fields.Add("StringValue", _dataSource[_currentRecordIndex]);
    if (!e.IsDesignMode)
        if (_currentRecordIndex >= _dataSource.Length)
            e.IsLastRecord = true;

Attaching my playground project (LL26, VS2019). Again: it might well be worth the effort to rewrite this and use data binding as this is much slicker. However I understand there’s not always enough time to redo things in a better way.

DefineFieldsSample.zip (10.0 KB)

1 Like

Appreciate your help. Your sample produced numerous errors when loaded. I believe it’s because the PC I’m working on has LL20 installed. I should have a newer version to try here. Do you have similar sample code for VB.Net?

If databinding is the way to go I’ll look into this. From reading forums and looking at code samples it seems my use for LL is quite different than many. There is no database or other data source to easily bind to. All of our reports are single page with data being generated on the fly in software. Data is coming from measurement devices such as volt meters etc. The result is numerous numeric and string arrays to be printed as columns (Fields) on the report. Variables are also passed and printed in various locations on the report. Currently I’m passing all arrays as individual fields and creating numerous .LST templates that use one or more of these as needed for a given report. What is the best way to achieve this thru databinding?

Yes, you need to adapt the namespaces in order to get this up and running with LL20. My VB.NET is not as fluent as my C#. Using Telerik’s code converter results in these snippets (corrections welcome):

Using LL As ListLabel = New ListLabel()
    LL.DefineFields += AddressOf LL_DefineFields
End Using


Private _dataSource As String() = New String() {"A", "B", "C"}
Private _currentRecordIndex As Integer = 0

Private Sub LL_DefineFields(ByVal sender As Object, ByVal e As DefineElementsEventArgs)
	(TryCast(sender, ListLabel)).Fields.Add("StringValue", _dataSource(_currentRecordIndex))

	If Not e.IsDesignMode Then
		_currentRecordIndex += 1
		If _currentRecordIndex >= _dataSource.Length Then e.IsLastRecord = True
	End If
End Sub

If you’d like to explore the databinding path, the ObjectDataProvider would probably be your best option. Here is a quick tutorial on adding custom data in addition to what’s available in the data source as well as using the ObjectDataProvider class.

None of the online C# to VB.NET translators worked correctly. Finally found the correct syntax which works.

LL.DefineFields += LL_DefineFields;

AddHandler LL.DefineFields, AddressOf LL_DefineFields


1 Like

© combit GmbH