Posted 18 December 2018, 4:45 am EST
vsFlexGrid8 (Light) BindToArray in VB.net
Posted by: SatishMatani on 18 December 2018, 4:45 am EST
-
-
Posted 18 December 2018, 7:43 pm EST
Hi Satish,
BindToArray method allows you to bind the VSFlexGrid control to a Visual Basic Variant Array or to another VSFlexGrid control, as explained here:
https://help.grapecity.com/componentone/NetHelp/vsflexgrid8/bindtoarraymethod.htmlIt has different parameters to be passed. You can go through the details on the above mentioned page itself.
Here is the example code snippet to bind VSFlexGrid to an array in VB.Net:
Dim arr(4, 4) As Object arr(2, 2) = 1 For i As Integer = 1 To 3 arr(i, 3) = 1 Next For i As Integer = 0 To 4 arr(i, 4) = 1 Next AxVSFlexGrid1.BindToArray(arr, 1, 0, 0, 0)
~Pragati
-
Posted 19 December 2018, 6:50 am EST
Thank you Pragati for a quick response.
I tried this but does not work. See below for my VB6 and VB.Net codes.
The messagebox in VB6 gives value of “1” but in VB.Net is blank. What am I doing wrong?'VB6______________________________________________________________________________
Public P(4, 4) ’ Defined in separate module
Private Sub Form_Load()
fg.BindToArray PDim i As Integer
For i = 1 To 4
fg.TextMatrix(i, 1) = i
NextEnd Sub
Private Sub Command1_Click()
MsgBox P(0, 0)
End Sub
'VB.Net________________________________________________________________________________
Module GlobalVariable
Public P(4, 8)
End ModulePublic Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
fg.BindToArray(P, 1, 0, 0, 0)Dim i As Integer For i = 1 To 4 fg.set_TextMatrix(i, 1, i) Next End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox(P(0, 0)) End Sub
End Class
-
Posted 26 December 2018, 2:28 am EST
Pargati,
Just wondering if you had a chance to look into my previous post. Bound Array does not seem to be updating per changes made to vsflexgrid as noted per following statement in the link you sent in vb.net:
When bound to an array, the grid displays values retrieved from the array and automatically writes any modifications back into the array.
-
Posted 13 January 2019, 11:31 pm EST
Hello Satish,
I am also able to observe the same at my end and hence I am discussing the issue with the developer [ID:361904]. I will get back to you once we receive some information from him.
Thanks,
Ruchir -
Posted 27 January 2019, 8:25 pm EST
Hello,
Following is the response received from the developer:
Sharing memory between native controls (e.q - ActiveX) and managed memory software (e.g. - .NET) is problematic as the memory in the ActiveX controls is fixed while objects in managed memory software the objects move around. Descriptions for the process involved can be found on the web - here are a couple of interest for this case:
https://docs.microsoft.com/en-us/dotnet/framework/interop/default-marshaling-for-strings
https://www.red-gate.com/simple-talk/dotnet/net-framework/5-tips-for-understanding-managed-unmanaged-interoperability-in-net/
VB6 passes arrays in the form of a SafeArray (see Microsoft documentation), so the Flexgrid8 BindToArray method is expecting a SafeArray of Variants as the first argument. SafeArrays are not part of the .NET object list, so the array is marshaled from the .NET structure to the SafeArray structure. To begin with, the default marshaling performed by .NET does not properly handle an array of variants that contain reference objects (i.e. - non-blittable is the term in the literature), but even if it did, the marshaling process only transfers the data and does not preserve the structure or automatically transfer the data changes back to the original .NET object.
For BindToArray to work properly, it would be necessary to create a SafeArray structure in .NET, fix it in memory and pass that to BindToArray. This is usually not worth the effort and beyond the scope of this discussion.
The customer might consider using the get_TextMatrix(row, col) method instead creating the SafeArray structure and binding it. This would allow the FlexGrid to maintain the data entirely while selecting the necessary data as needed.
If the customer is binding the array to other .NET objects, then use get_TextMatrix()/set_TextMatrix and events to update a .NET array as they occur in theFlexGrid (and visa versa).Thanks,