I am making a game in Visual Basic that has to contain a high score table. I am using a ListView
control named lstscores
to store rows of scores in 2 columns called Name
and Score
. The user has to guess words that are entered into a ListBox called lstwords
when correct. I have set up 2 things in Application.Settings
: settingname
and settingscore
both with type: System.Collections.Specialized.StringCollectino
, Scope: user
and Value: Nothing
.
When user clicks on a save button, I basically want to take the username and score and store it in the settings respectively. So when I open the form up next time I can load the settings back into the same ListView
control.
I have been researching for a few hours, and I haven't been able to find anything exactly suited to my needs.
I cannot provide my code, as i have tried everything possible to my knowledge, and nothing has worked.
If someone could please give me advice or a direction on how to go about doing this, I would be very grateful.
Thanks
Dim arr(1) As String
Dim score As Integer
inputname = txtname.Text
score = lstwords.Items.Count
arr(0) = inputname
arr(1) = score
lstscores.Items.Add(New ListViewItem(arr))
You can use combination of Save()
and Reload()
methods to store your data. When user clicks on Save button, you can iterate your ListView adding content ListView.Items[n]
to collection of names and content of sub-item ( ListViewItem.SubItems[0]
) to collection of scores. Then, use My.Settings.Save()
to save your data. To have your data back in ListView
after start, use My.Settings.Reload()
(in for example Form.Load
event) and iterate it back. Here's an example of saving iteration (not tested):
For Each it0 in lstscores.Items
My.Settings.settingname.Add(it0.Text)
My.Settings.settingscore.Add(it0.SubItems[0].Text)
Next
My.Settings.Save()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.