Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27360

VS 2010 saving and loading listview

$
0
0
Ok, many of you have helped me recently with a listview problem, well, I hit another one. Basically, I have a score bored in the form of a listview, the position in the right hand column, player name in middle and points on the right, this information needs to be saved, BUT, and heres the biggy, I only need the sub items stored as depending on the players next score the position is unknown. How would I save just the sub items, and then on form load have them load up in the listview again showing the players position?

Heres some code

Code:

Public Class Main

    Public Structure players
        Dim player As String
        Dim points As Integer
    End Structure

    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'creating the fields for listview
        Dim team() As players = New players() {New players With {.player = My.Settings.player, .points = My.Settings.score}}

        'arranging by points
        Array.Sort(team, Function(x, y) y.points.CompareTo(x.points))

        'adding fields to listview
        League.Items.AddRange(Enumerable.Range(0, team.Length).Select(Function(x) New ListViewItem(New String() {(x + 1).ToString, team(x).player, team(x).points.ToString})).ToArray)

    End Sub

    Private Sub PlayerButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PlayerButton.Click
        'open form playerss
        Dim playerss As New Playerss
        playerss.Show()
    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'save textbox text for later
        My.Settings.score = TextBox1.Text

        'creating fields for listview
        Dim team() As players = New players() {New players With {.points = My.Settings.score}}
        'arrange list by points
        Array.Sort(team, Function(x, y) y.points.CompareTo(x.points))
        'add to listview
        League.Items.AddRange(Enumerable.Range(0, team.Length).Select(Function(x) New ListViewItem(New String() {(x + 1).ToString, team(x).player, team(x).points.ToString})).ToArray)
        'update listview
        League.Update()
    End Sub
End Class


Viewing all articles
Browse latest Browse all 27360

Trending Articles



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