Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

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 user's 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

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

  • Leaders
Posted

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

 

This should give an idea of what I'm talking about...

   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

--tim
  • *Experts*
Posted

Thanks Tim, but I would like to stick with the listview, although I do see your point. I've currently got the data in a string format, much like a CSV format, that is split into an array. From there I'd like to multiply each member of the array by a factor and display the results onto the listview. Unfortunately, the tables I'm working with are not uniform in any way and I don't think a standard database approach will work.

 

Thanks

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

  • *Experts*
Posted (edited)

Never mind, I've got it.

 

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

 

       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.

Edited by divil

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...