Results 1 to 10 of 10

Thread: [RESOLVED] DataGridView output not showing?

Threaded View

  1. #1

    Thread Starter
    Member din0's Avatar
    Join Date
    Aug 2011
    Location
    Indianapolis
    Posts
    34

    Resolved [RESOLVED] DataGridView output not showing?

    For a class project I'm supposed to write a program that requests a team as input and displays the players from that team in the first column. The players should be sorted alphabetically by their last name, and if they have the same name they should be sorted by first name accordingly. My program compiles and I'm fairly certain that I've done most of it correctly. The second column should be filled with the batting average of the corresponding player from the left column.

    My problems are as follows:

    1) I can't get the DGV output to show correctly, it posts the player's name with the batting average of that player in the following downward cell.

    2) I'm not sure how to further use the .Split method to separate the first and last name after already separating the name from team/at bats/hits, and can't find any info regarding this topic. Also, I can't figure out how to sort in reverse, I've only seen the Ascending and Descending options so far for sorting.

    3) Is the way I've figured the batting average the most efficient/correct way, or is there another better way?

    Thanks in advance to anyone that helps, it's greatly appreciated by a knowledge-hungry newcomer!



    Code:
    Public Class danbrockplayers
        Structure player
            Dim name, team, atBats, hits, average
        End Structure
    
        Dim players() As player
    
        Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
            gridStats.Rows.Clear()
    
            Dim query = From player In players
                        Where player.team = txtTeam.Text
                        Order By player.name
                        Select player.name, player.average
    
            For Each player In query
                gridStats.Rows.Add(player.name)
                gridStats.Rows.Add(player.average)
            Next
    
        End Sub
    
        Private Sub danbrockplayers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Place the data for each player into the array players
    
            Dim allPlayers() = IO.File.ReadAllLines("Baseball.txt")
            Dim n = allPlayers.Count - 1
            ReDim players(n)
            Dim line As String  'holds data for a single player
            Dim data() As String
    
            For i As Integer = 0 To n
                line = allPlayers(i)
                data = line.Split(","c)
                players(i).name = data(0)
                players(i).team = data(1)
                players(i).atBats = CInt(data(2))
                players(i).hits = CInt(data(3))
                players(i).average = players(i).hits / players(i).atBats
            Next
        End Sub
    End Class
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width