Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to display results

Status
Not open for further replies.

Bluejay07

Programmer
Mar 9, 2007
780
CA
Hello,

Before I begin please note that I have some programming experience using VB.net, although most of my background comes from VB6. I am currently using VB.net 2005.

I am currently working on a personal project (so that I can become more knowledgeable in VB.net) based off of a board game in which I am tracking the score of each player during each of their turns. I am currently storing the scores in a string (a separate string for each player).

At any time throughout the game, the user will be able to view the scoring history of all players. The history will be displayed on a new form.

Here is an example of scores:
Sam|30|5|15|
John|-5|-5|-5|21|22|3|14|
Julia|5|3|-5|51|6|

As you may notice, not everyone's score has the same number of entries although John has the highest amount with 7 entries. I am wondering what the best method would be to display the history of the player scores. I was originally thinking of using a datagridview, although creating the columns dynamically (based on the player with the highest amount of entries) may be a bit tedious.

Would anyone have a suggestion on a way to display the entries and depending on the suggestion, if you could provide some code to get me started would be a great help.

Thank you.

If at first you don't succeed, then sky diving wasn't meant for you!
 
So far I'm still using a datagridview and things seem promising. If it works, I will post my solution.

If at first you don't succeed, then sky diving wasn't meant for you!
 

I would flip the grid, and have the player names as the columns and the scores as the rows. That way you don't need to add columns for each score, just for each player,which should be less tedious.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks for the suggestion, although since I am dealing with scores, it's much easier to read them horizontally rather than vertically.

So far the grid is being created and the names populate correct. I am having difficulty in displaying the scores. Something similar to the following works:
Code:
dgvHistory.Rows.Insert(i, l_strNameArr(i), "5", "10", "-5")

How do I populate the number score values? I have tried:
Code:
dgvHistory.Rows.Insert(i, l_strNameArr(i), m_strPlayer1Hist)

and

dgvHistory.Rows.Insert(i, l_strNameArr(i), m_strPlayer1Hist.Split(","))

and

Dim l_strPlay1Arr() As String
l_strPlay1Arr = m_strPlayer1Hist.Split(",")
dgvHistory.Rows.Insert(i, l_strNameArr(i), l_strPlay1Arr)
m_strPlayer1Hist is the original string of scores separated by commas.

The above places the entire string in one cell rather than placing them in separate cell.

If at first you don't succeed, then sky diving wasn't meant for you!
 
I have also tried to format the string with quotes and commas. The split would be using a semicolon.
Code:
If m_strPlayer1Hist.Trim = String.Empty Then
   m_strPlayer1Hist = """" & lblTurnTotal.Text & """"
Else
   m_strPlayer1Hist = m_strPlayer1Hist & ",;" & """" & lblTurnTotal.Text & """"
End If

That didn't work either.



If at first you don't succeed, then sky diving wasn't meant for you!
 
I discovered I had to place the scores in the cells individually rather than trying to place everything in the cells during the insert. Here is the solution that worked for me:
Code:
dgvHistory.Rows.Insert(i, l_strNameArr(i))

For j = 0 To UBound(l_strPlay1Arr)
   dgv.Item((j + 1), dgv.Rows.Count - 1).Value = l_strPlay1Arr(j)
Next

The j + 1 was because the first cell already had the player name in it.



If at first you don't succeed, then sky diving wasn't meant for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top