locked
Data Grid View Controls?

    Question

  • Hi,

    I have to turn this program in TOMORROW! I can't seem to figure out how to do this section. If someone could help me out with the first part, and I can do the second part.

    I have two text files, one is a single dimensional array, and one is a two dimensional array. One titled "Months.txt" and the other "Rain.txt".

    The problem is I have to read those into an array, and then after that, use a query to pull the information and display it into a data grid view style box.

    The problem I'm facing is when I pull the "Months.txt" text file, which has the months in order from January....December, and try to display it in the data grid it puts the length of the names of the months, not the actual months. Can someone please help me on this matter? I've tried to no avail. Also, how would you add all of the numbers in a single row of a two-dimensional array to give a total to display in the data grid? Also, the column? There's no code for this in our book. At all. Sample code is below.

    Public Class frmRain
    
      Dim months() As String = IO.File.ReadAllLines("months.txt")
      Dim Rain(4, 11)
      Dim numRows() As String = IO.File.ReadAllLines("rain.txt")
      Dim Years() As Integer = {"1986", "1987", "1988", "1989", "1990"}
    
      Private Sub frmRain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
      End Sub
    
      Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        Dim line As String
        Dim rainData() As String
        For i As Integer = 0 To Rain.GetUpperBound(0)
          line = numRows(i)
          rainData = line.Split(","c)
          For j As Integer = 0 To Rain.GetUpperBound(1)
            Rain(i, j) = CDbl(rainData(j))
          Next
        Next
        Dim average = From month In months
               Select month
        dgvAverage.DataSource = average.ToList
        dgvAverage.CurrentCell = Nothing
      End Sub
    
      Private Sub dgvTotal_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvTotal.CellContentClick
    
      End Sub
    
      Private Sub dgvAverage_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvAverage.CellContentClick
    
      End Sub
    End Class
    
    
    Sunday, December 05, 2010 11:03 PM

All replies

  • What is the code you are using to display the month names in the datagrid?

    Your Average calculation is based on the months array - I believe it should be based on the Rain() array.

    Sunday, December 05, 2010 11:28 PM
  •  Dim average = From month In months
       Select month
     dgvAverage.DataSource = average.ToList
     dgvAverage.CurrentCell = Nothing
    
    
    This is the section I'm referring too. I'm not actually "averaging" anything yet, I'm just trying to display the months read in from a text file into the data grid. It doesn't display the names of the months, just the lengths of the names of the months.
    Sunday, December 05, 2010 11:39 PM
  • In that case the problem is that you aren't actually putting the month name anywhere. You are updating a data source with a list.  Is the data source bound to the DGV? 
    Monday, December 06, 2010 12:37 AM