-
Feb 1st, 2012, 03:08 PM
#1
Thread Starter
Member
Adding rows to bottom of datagrid view
I have what should be a simple problem to fix.
I am trying to insert an initial line (0) into a datagridview (named params). The program will then read each cell in that row, pass them through a function and return values be placed into the next line (1). This will continue until one of the parameters reaches some set point.
The problem that I am having is that when I try to insert a new line, it appears above the initial one and not below it like I would like it to.
Here's my code so far:
Code:
Private Sub HurricaneWinds_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim init_xrange() As Double = New Double() {0.0, 0.0, 0.0, 40.0, 0.0}
For i As Integer = 0 To 4
params(i, 0).Value = init_xrange(i)
Next
Dim xx(4) As Double
For j As Integer = 1 To 10
Dim prange() As Double = New Double() {CDbl(DragCo.Text.Trim), CDbl(WindVelCoef.Text.Trim), CDbl(WindVelExp.Text.Trim), CDbl(Gravity.Text.Trim)}
Dim xrange() As Double = New Double() {CDbl(params(0, j - 1).Value), CDbl(params(1, j - 1).Value), CDbl(params(2, j - 1).Value), CDbl(params(3, j - 1).Value), CDbl(params(4, j - 1).Value)}
xx = rk4(CInt(NumTimesteps.Text.Trim), CDbl(TimeStep.Text.Trim), xrange, prange)
Dim item As New DataGridViewRow
item.CreateCells(params)
With item
.Cells(0).Value = xx(0)
.Cells(1).Value = xx(1)
.Cells(2).Value = xx(2)
.Cells(3).Value = xx(3)
.Cells(4).Value = xx(4)
End With
params.Rows.Add(item)
Next
End Sub
And a picture of the problem:
Any suggestions?
Thanks
-
Feb 1st, 2012, 03:27 PM
#2
Re: Adding rows to bottom of datagrid view
Why not add the rows as follows where the DataGridView columns are predefined.
Code:
YourDataGridViewName.Rows.Add(New Object() {xx(1),xx(2),xx(3),xx(4)})
-
Feb 1st, 2012, 03:34 PM
#3
Thread Starter
Member
Re: Adding rows to bottom of datagrid view
Originally Posted by kevininstructor
Why not add the rows as follows where the DataGridView columns are predefined.
Code:
YourDataGridViewName.Rows.Add(New Object() {xx(1),xx(2),xx(3),xx(4)})
Mainly because I don't know how many rows are going to need to be created. Depending on the input parameters it could vary between 5 and hundreds.
My intention is to create a new row on the each time it goes through the For loop (which I will eventially convert to a 'do while' once this is working).
-
Feb 1st, 2012, 05:33 PM
#4
Re: Adding rows to bottom of datagrid view
Originally Posted by catoctinwx
Mainly because I don't know how many rows are going to need to be created. Depending on the input parameters it could vary between 5 and hundreds.
My intention is to create a new row on the each time it goes through the For loop (which I will eventially convert to a 'do while' once this is working).
The code I provided will add a row each time but what your code is doing is clearing cells because of CreateCells method.
I would suggest trying YourDataGridViewName.Rows.Add and if you have a great deal of rows or not use a try/finally as shown below
Code:
DataGridView1.SuspendLayout()
Try
' add rows
Finally
DataGridView1.ResumeLayout()
End Try
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|