Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42359

VS 2010 How to pass a (variable size) custom datatype array to a usercontrol property?

$
0
0
Hi,

I am making my own chart control, in which a data point at location x,y is coloured according to a third parameter.
My vb solution has two projects : the usercontrol project, and a testapplication, in which I place the usercontrol on a form to test it.

In order to pass the X,Y and Color data (all of the Single datatype) to the control, I created a structure (within the usercontrol class) like so:

Code:

Structure XYData
        Dim XYDate As DateTime
        Dim x, y, c As Single
    End Structure

The datetime is not needed yet. The usercontrol's property name where the data should arrive, is called "List".

These are my very first steps into user control creation. I realise my approach may be completely wrong. If so, let me know...

Since the XYData-structure is defined in the usercontrol class, I need to define the same structure in my testapplication to be able to send data from there to the usercontrol. However, there's no fooling VB.NET, as it tells me the testapplication XYData-structure is (and I quote) "not derived" from the usercontrol class XYData-type. Making the usercontrol class' XYData-structure public doesn't solve this. How do I solve this?

Since the amount of datapoints is variable , the length of the t()-array that holds the records, is also variable.

As I understand it, passing something "ByVal" will send a COPY of the data, while "ByRef" is passing a POINTER to existing data in memory. A quick lookaround on the internet shows me that within a usercontrol class, it is common sense not to access a property directly, but to copy it to an internal (private) variable, which is used to Set and Get the property value. Since my control's List-property will only receive data, I assume i could use the list()-array directly, without copying the whole list to a private dim'ed array variable within the user class. So I'm guessing I should use ByRef in this case?

I have a workaround in mind, but I find it to be a big detour : having the testapplication to write all data to records in a textfile, pass the textfilename to the usercontrol as a property, and then read the textfile within the usercontrol class code, construct the chart and delete the textfile. I prefer passing the data without using a file, so that's why I ask for help...

Viewing all articles
Browse latest Browse all 42359

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>