JesperSP
Member
The following snip of simple code runs pretty slow on my computer, and I suspect that it is due to excessive memory usage, since the program reports using >1GB mem according to TaskManager. Am I using the DataGridView in a wrong way? 
Instructions: Make a windowsforms application and put 2x button and 1xDataGridView on it. Push button1 and then button2 - sort the data in the DataGridView by a different col and push button2 again. It'll go above 1GB mem usage! Basically I need to display a lot of data to a user and allow the user to sort the data and generate something from them. Can this be done in a more optimal way?
Cheers,
Jesper
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
	
		
			
		
		
	
				
			Instructions: Make a windowsforms application and put 2x button and 1xDataGridView on it. Push button1 and then button2 - sort the data in the DataGridView by a different col and push button2 again. It'll go above 1GB mem usage! Basically I need to display a lot of data to a user and allow the user to sort the data and generate something from them. Can this be done in a more optimal way?
Cheers,
Jesper
			
				VB.NET:
			
		
		
		Public Class Form1
    Public dt As DataTable
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        dt = New DataTable
        For i As Integer = 1 To 18
            dt.Columns.Add(New DataColumn("col" & i, System.Type.GetType("System.Double")))
        Next
        For i As Integer = 0 To 300000
            Dim dr As DataRow = dt.NewRow()
            For t As Integer = 0 To 17
                dr.Item(t) = Rnd() * 100
            Next
            dt.Rows.Add(dr)
        Next
        DataGridView1.DataSource = dt
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
         For Each dr As DataGridViewRow In DataGridView1.Rows
            If dr.Cells("col1").Value > 50 Then
                'do something
            End If
        Next
    End Sub
End Class
	
			
				Last edited: