Link to home
Start Free TrialLog in
Avatar of Alyanto
AlyantoFlag for United Kingdom of Great Britain and Northern Ireland

asked on

DataGridView

I am missing something in my sample code that allows me to save changes in the datagrid back to the structure.  Could I get a good pointer as to what that might be?

Public Class Form1
    Private Tests As New Generic.List(Of testdata)
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Tests.Add(New testdata("John", "Smith", 48))
        Tests.Add(New testdata("Jane", "Smith", 45))
        Tests.Add(New testdata("Andy", "Smith", 19))
        Tests.Add(New testdata("Sally", "Smith", 23))
        With Me.DataGridView1
            Dim binder As New BindingSource
            binder.DataSource = Tests
            .DataSource = binder
            .ReadOnly = False
            .EditMode = DataGridViewEditMode.EditOnKeystroke
            .Columns("Forename").HeaderText = "First Name"
            .Columns("Forename").ReadOnly = True
            .Columns("Surname").HeaderText = "Family Name"
            .Columns("Surname").ReadOnly = True


        End With


    End Sub

    Private Sub DataGridView1_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit

    End Sub

    Private Sub DataGridView1_CellLeave(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave

    End Sub
End Class

Public Structure testdata
    Public Sub New(FName As String, SName As String, Years As Integer)
        Forename = FName
        Surname = SName
        Age = Years
    End Sub

    Private _Forename As String
    Public Property Forename As String
        Get
            Return _Forename
        End Get
        Set(value As String)
            _Forename = value
        End Set
    End Property

    Private _Surname As String
    Public Property Surname As String
        Get
            Return _Surname
        End Get
        Set(value As String)
            _Surname = value
        End Set
    End Property

    Private _Age As Integer
    Public Property Age As Integer
        Get
            Return _Age
        End Get
        Set(value As Integer)
            _Age = value
        End Set
    End Property

    Public Property RecordColour As Color

End Structure
ASKER CERTIFIED SOLUTION
Avatar of srikanthreddyn143
srikanthreddyn143

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Alyanto

ASKER

Yep that seems to be the issue.  Thanks again :)
Avatar of Alyanto

ASKER

A1+ result again, thanks :)