Link to home
Start Free TrialLog in
Avatar of Skale
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.

                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

Open in new window


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

Open in new window


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))

Open in new window


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.
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

You could do this:

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)
Avatar of Skale
Skale

ASKER

It wroted all of them in one single cell like : Model,$F_shackle_chassis_le,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
Avatar of Skale
Skale

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial