How to add data to a DataGridView from a Loop?

  • Thread starter Thread starter Alexanderkng
  • Start date Start date
A

Alexanderkng

Guest
Hello everyone,

Some weeks ago I asked about how to add data to a Listview and everything went fine. This time, I'm trying to add data to a Datagridview in the same way, but I noticed that Datagridviews and Listviews works differently. This is the way I fill up my Listview with data:


' Cálculo para Lista de Carga 1
With ListvCarga1
.View = View.Details
.Columns.Add("Punto", 40, HorizontalAlignment.Center)
.Columns.Add("X (m)", 50, HorizontalAlignment.Center)
.Columns.Add("Y (cm)", 70, HorizontalAlignment.Center)
.Columns.Add("V (Kgf)", 70, HorizontalAlignment.Center)
.Columns.Add("M (Kgf*m)", 70, HorizontalAlignment.Center)
End With
'


''''''''''''''''''''''''''''''''''''''''''''CALCULO CON 1 CARGA


Dim i As Integer
Dim XC1 As Decimal
'
If combobCantidadCargas.Text = 1 Then 'Existe solo 1 carga

i = 0
XC1 = 0
' de extremo izquierdo a posicion de carga 1
While XC1 <= dblPosicionCarga1
Dim lviextc1 As New ListViewItem((XC1 / 0.05 + 1).ToString("0"))
lviextc1.SubItems.Add((XC1).ToString("0.00"))
lviextc1.SubItems.Add(((dblCarga1 * 10 * dblCaracteristicaSistema) / (dblBalasto * dblAncho) * 1 / ((Math.Sinh(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2 - (Math.Sin(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2) * (2 * Math.Cosh(dblCaracteristicaSistema * XC1 * 100) * Math.Cos(dblCaracteristicaSistema * XC1 * 100) * decAaC1 + (Math.Cosh(dblCaracteristicaSistema * XC1 * 100) * Math.Sin(dblCaracteristicaSistema * XC1 * 100) + Math.Sinh(dblCaracteristicaSistema * XC1 * 100) * Math.Cos(dblCaracteristicaSistema * XC1 * 100)) * decBbC1)).ToString("0.000000"))
lviextc1.SubItems.Add((dblCarga1 * 1000 * 1 / ((Math.Sinh(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2 - (Math.Sin(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2) * ((Math.Cosh(dblCaracteristicaSistema * XC1 * 100) * Math.Sin(dblCaracteristicaSistema * XC1 * 100) + Math.Sinh(dblCaracteristicaSistema * XC1 * 100) * Math.Cos(dblCaracteristicaSistema * XC1 * 100)) * decAaC1 + (Math.Sinh(dblCaracteristicaSistema * XC1 * 100) * Math.Sin(dblCaracteristicaSistema * XC1 * 100)) * decBbC1)).ToString("0.00"))
lviextc1.SubItems.Add(((dblCarga1 * 10 / dblCaracteristicaSistema) * 1 / (2 * ((Math.Sinh(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2 - (Math.Sin(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2)) * (2 * Math.Sinh(dblCaracteristicaSistema * XC1 * 100) * Math.Sin(dblCaracteristicaSistema * XC1 * 100) * decAaC1 + (Math.Cosh(dblCaracteristicaSistema * XC1 * 100) * Math.Sin(dblCaracteristicaSistema * XC1 * 100) - Math.Sinh(dblCaracteristicaSistema * XC1 * 100) * Math.Cos(dblCaracteristicaSistema * XC1 * 100)) * decBbC1)).ToString("0.00"))

ListvCarga1.Items.Add(lviextc1)

i += 1
XC1 = i * 0.05

End While

'de posicion de carga 1 a extremo derecho
i = 0
XC1 = dblPosicionCarga1

While XC1 <= dblLongitud
Dim lvic1ext As New ListViewItem((XC1 / 0.05 + 2).ToString("0"))
lvic1ext.SubItems.Add((XC1).ToString("0.00"))
lvic1ext.SubItems.Add(((dblCarga1 * 10 * dblCaracteristicaSistema) / (dblBalasto * dblAncho) * 1 / ((Math.Sinh(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2 - (Math.Sin(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2) * (2 * Math.Cosh(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) * Math.Cos(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) * decCcC1 + (Math.Cosh(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) * Math.Sin(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) + Math.Sinh(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) * Math.Cos(dblCaracteristicaSistema * (dblLongitud - XC1) * 100)) * decDdC1)).ToString("0.000000"))
lvic1ext.SubItems.Add((-dblCarga1 * 1000 * 1 / ((Math.Sinh(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2 - (Math.Sin(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2) * ((Math.Cosh(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) * Math.Sin(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) + Math.Sinh(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) * Math.Cos(dblCaracteristicaSistema * (dblLongitud - XC1) * 100)) * decCcC1 + (Math.Sinh(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) * Math.Sin(dblCaracteristicaSistema * (dblLongitud - XC1) * 100)) * decDdC1)).ToString("0.00"))
lvic1ext.SubItems.Add(((dblCarga1 * 10 / dblCaracteristicaSistema) * 1 / (2 * ((Math.Sinh(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2 - (Math.Sin(dblCaracteristicaSistema * dblLongitud * 100)) ^ 2)) * (2 * Math.Sinh(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) * Math.Sin(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) * decCcC1 + (Math.Cosh(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) * Math.Sin(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) - Math.Sinh(dblCaracteristicaSistema * (dblLongitud - XC1) * 100) * Math.Cos(dblCaracteristicaSistema * (dblLongitud - XC1) * 100)) * decDdC1)).ToString("0.00"))

ListvCarga1.Items.Add(lvic1ext)

i += 1
XC1 = dblPosicionCarga1 + i * 0.05

End While

End If


What I'm doing there, and what I want to do with DataGridViews is:

- Define Columns width and headers. This is crucial to keep a constant appereance on all DataGridViews.

- Create a loop from 0 to Load Position (dblPosicionCarga1) on which I calculate deflection, shear and bending moment every X interval.

- When i reach dblPosicionCarga1 with first loop. Second loop starts inmediately from dblPosicionCarga1 to dblLongitud (wich is the lenght of the beam evaluated). Important: dblPosicionCarga1 is repeated on the list (intentionally).

It is important to point out that both loops go on the same DataGridView, without erasing each other.

Is there a way to do this? Thanks in advance for your help and guidance, guys.

Continue reading...
 
Back
Top