Arrays and Listview

DiverDan

Well-known member
Joined
Jan 16, 2003
Messages
645
Location
Sacramento, CA
User Rank
*Experts*
I have an Integer single dimension array that I need to multiply each element in the array by a factor then display the results into a multi columned listview. The length of the array will vary depending on the users selection.

Dim NumberArray() = {1,2,3,4} Or Dim numberArray = {1,2} .etc

How can I multiply each element of the array by a new factor then display the results into a multi column listview?

Thanks
 
Does it have to be a listview? or will a datagrid do? The reason I ask is that itd be trivial to do using an expression column on a datatable behind a datagrid, but I think youre going to have to do it manually with listview, who knows though, Im not very good at GUI stuff maybe someone else will have an idea.

This should give an idea of what Im talking about...
Code:
    Public Sub Init()
        Me.DataSet1.Tables.Add("mytable")
        Me.DataSet1.Tables("mytable").Columns.Add(New DataColumn("Initial_Val", GetType(Integer)))
        Me.DataSet1.Tables("mytable").Columns.Add("Factor", GetType(Integer), "Initial_Val * 5")
        Dim r As DataRow
        r = Me.DataSet1.Tables("mytable").NewRow()
        r("Initial_Val") = 5
        Me.DataSet1.Tables("mytable").Rows.Add(r)
        Me.DataGrid1.DataSource = Me.DataSet1
        Me.DataGrid1.DataMember = "mytable"
    End Sub
 
Thanks Tim, but I would like to stick with the listview, although I do see your point. Ive currently got the data in a string format, much like a CSV format, that is split into an array. From there Id like to multiply each member of the array by a factor and display the results onto the listview. Unfortunately, the tables Im working with are not uniform in any way and I dont think a standard database approach will work.

Thanks
 
Never mind, Ive got it.

Loading a CSV array into a multi column listview, with a multiplication factor:

Code:
        Get_NEC_Tables()
        lvConductors.Items.Clear()

        Dim AmountOfWires() As String
        AmountOfWires = WireQty.Split(",")

        Dim FirstItem As ListViewItem
        Dim OtherItems As ListViewItem.ListViewSubItem
        Dim count As Byte
        For count = 0 To AmountOfWires.GetUpperBound(0)
            If count = 0 Then
                FirstItem = New ListViewItem(CInt(FillFactor * AmountOfWires(count)).ToString())
            Else
                OtherItems = New ListViewItem.ListViewSubItem()
                OtherItems.Text = CInt(FillFactor * AmountOfWires(count)).ToString()
                FirstItem.SubItems.Add(OtherItems)
            End If
        Next
        lvConductors.Items.Add(FirstItem)

There is probably a better way of doing this, which I would appreciate seeing, but at least it works.
 
Last edited by a moderator:
Back
Top