Skale
asked on
How to add rows to DataGridView with list values in vb.net
Hello,
I'm using below code to add values to datagridviews according to their types.
I have also function like below and it's returning a list of double.
In normally if the output value number is certain for each type of force it'll be easy for me to add rows like that.
As you can see if i know "result" list has 3 items it's easy for me to add.
But if i dont know the list size/ item number how is it possible to add row to DataGridView?
Thank you.
I'm using below code to add values to datagridviews according to their types.
For Each force In forceList
Dim tp As TabPage = DirectCast(tabCtrl.Controls("tabCheckForceOut_" & force.type.val.ToString), TabPage)
Dim dgv As DataGridView = DirectCast(tp.Controls("dgvCheckForceOut_" & force.type.val.ToString), DataGridView)
dgv.Rows.Add(force.parent, force.name)
Next
I have also function like below and it's returning a list of double.
Private Function EvaluateForce(ByVal xObj As IScrForce) As List(Of Double)
Dim ovNumber As Integer = xObj.getNumOv
Dim resList As New List(Of Double)
For i As Integer = 1 To ovNumber
resList.Add(CoreGlobal.Base.Server.Spck.Slv.eval("FORCEOV(" + xObj.fullName + "," & i & ")"))
Next
Return resList
End Function
In normally if the output value number is certain for each type of force it'll be easy for me to add rows like that.
Dim result As List (Of Double) = EvaluateForce(force)
dgv.Rows.Add(force.parent, force.name, result.item(0), result.item(1), result.item(2))
As you can see if i know "result" list has 3 items it's easy for me to add.
But if i dont know the list size/ item number how is it possible to add row to DataGridView?
Thank you.
ASKER
It wroted all of them in one single cell like : Model,$F_shackle_chassis_l e,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
dim vals As String = force.Parent & "," & force.Name
For i As Integer = 0 to result.Count-1
vals = vals & "," & result(i)
Next
dgv.rows.add(vals)