Search code examples
vb.netarraysdatagridviewstructurebindingsource

VB.Net DataGridView BindingSource and Structure Array not updating


I'm having some issues and it's all explained in some simplified code

I have a structure

Public Structure myStruct
    Public Property name As String
    Public Property span As Double
    Public Property offs As Double
End Structure

Which is instantiated in a Singleton object as follow

Public myValues(10) As myStruct

Then on a form, I'm using the structure as the DataSource for a SourceBinder and the binder as DataSource for a DataGridView.

On loading the form, I get all the values into the binder

    For i As Integer = 0 To 9
        binder.Add(singleton.getRef.myValues(i))
    Next i

All the values are shown on the grid.

User is supposed to be able to change the values, which should reflect on myValues but no matter, what code I put on CellValueChanged or CurrentChanged. I can't make it reflect the changes.

Using breakbpoints on those events, I noticed that grid.row().cell().values and binder.current never changes.

I tried also placing a button and directly changing myValues and reseting the binder binder.ResetBindings(False) and nothing happens.

As far as I saw all ReadOnly properties are set to false.

I've also tried setting VirtualMode to true on the grid and catching CellValuePushed and CellValueNeeded events but those are never called. (that was on a guessing base)

I'm really out of ideas on this one, if anyone can help me!

thanks.


Solution

  • Try using a class instead:

    Public Class myStruct
      Public Property name As String
      Public Property span As Double
      Public Property offs As Double
    End Class