Hi everyone,

I just had a quick question on how to go about getting data populated from a data grid view to an array of structures?

I have a data grid view with 6 fields and 10 records that match elements in my array.

I declared a list of songs based off of my structure Song.

Public Module structs
    Structure Song
        'members
        Public SongTitle As String
        Public CdName As String
        Public ReleaseDate As Date
        Public Genre As String
        Public Artist As String
        Public CdCost As Double
    End Structure

..................

Private SongList As New List(Of Song)

My goal is to read in the data from my data grid view and store it in my array of structures called songList.

I'm also trying to output the values of each element as I go into a seperate text box to make sure it was read into the array of structures.

I've tried some sample code below but I keep getting an argument out of range exception and it points to the second line in my code below.

thx

For curRow = 0 To 9

            dgvSongs.Rows(curRow).Cells(0).Value = SongList(curRow).SongTitle
            txtSongs.Text += SongList(curRow).SongTitle + ControlChars.NewLine
            dgvSongs.Rows(curRow).Cells(1).Value = SongList(curRow).CdName
            txtSongs.Text += SongList(curRow).CdName + ControlChars.NewLine
            dgvSongs.Rows(curRow).Cells(2).Value = SongList(curRow).ReleaseDate
            txtSongs.Text += SongList(curRow).ReleaseDate.ToString + ControlChars.NewLine
            dgvSongs.Rows(curRow).Cells(3).Value = SongList(curRow).Genre
            txtSongs.Text += SongList(curRow).Genre + ControlChars.NewLine
            dgvSongs.Rows(curRow).Cells(4).Value = SongList(curRow).Artist
            txtSongs.Text += SongList(curRow).Artist + ControlChars.NewLine
            dgvSongs.Rows(curRow).Cells(5).Value = SongList(curRow).CdCost.ToString
            txtSongs.Text += SongList(curRow).CdCost.ToString

        Next

I noticed that on the example given to me, the first field wasn't an * but was filled with data so the cell started at 0. I have a arrow in the first field in my data grid view so I tried starting the cell value with 1 to skip that but it's still pointing to that beginning line and giving me the argument out of range exception error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.