Hi Im trying to achieve something which seems simple but is proving difficult. I have listview1 which will display the values of two textbox's when a button is clicked. I have listview2 which will make a calculation based on the two values in listview1 when a button is clicked. What i would like to achieve is how to get the total of the rows in listview2 and display in the last column of listview2. Also is there a easy way of doing this as my code seems a bit long winded because i have added 10 columns in listview which might not be needed. I have included my code.
Many thanks for any help as this is a real headache for me.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreateListview1()
CreateListview2()
TextBox1.Text = 10
TextBox2.Text = 15
End Sub
Public Sub CreateListview1()
ListView1.View = View.Details
ListView1.GridLines = True
ListView1.Columns.Add("Textbox1", 70, HorizontalAlignment.Left)
ListView1.Columns.Add("Textbox2", -2, HorizontalAlignment.Left)
End Sub
Public Sub CreateListview2()
ListView2.View = View.Details
ListView2.GridLines = True
ListView2.Columns.Add("Number", 50, HorizontalAlignment.Left)
ListView2.Columns.Add("(Row 1 Textbox1* Row 1 textbox2)/number", 150, HorizontalAlignment.Left)
ListView2.Columns.Add("(Row 2 Textbox1* Row 2 textbox2)/number", 150, HorizontalAlignment.Left)
ListView2.Columns.Add("(Row 3 Textbox1* Row 3 textbox2)/number", 150, HorizontalAlignment.Left)
ListView2.Columns.Add("(Row 4 Textbox1* Row 4 textbox2)/number", 150, HorizontalAlignment.Left)
ListView2.Columns.Add("(Row 5 Textbox1* Row 5 textbox2)/number", 150, HorizontalAlignment.Left)
ListView2.Columns.Add("(Row 6 Textbox1* Row 6 textbox2)/number", 150, HorizontalAlignment.Left)
ListView2.Columns.Add("(Row 7 Textbox1* Row 7 textbox2)/number", 150, HorizontalAlignment.Left)
ListView2.Columns.Add("(Row 8 Textbox1* Row 8 textbox2)/number", 150, HorizontalAlignment.Left)
ListView2.Columns.Add("(Row 9 Textbox1* Row 9 textbox2)/number", 150, HorizontalAlignment.Left)
ListView2.Columns.Add("(Row 10 Textbox1* Row 10 textbox2)/number", 150, HorizontalAlignment.Left)
End Sub
Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calculate.Click
ListView2.Items.Clear()
For i = 1 To 10 Step 1
Dim item2 As New ListViewItem(i)
ListView2.Items.AddRange(New ListViewItem() {item2})
For row = 0 To ListView1.Items.Count - 1
item2.SubItems.Add(Formula(ListView1.Items(row).SubItems(0).Text, ListView1.Items(row).SubItems(1).Text, i))
Next
Next
End Sub
Private Function Formula(ByVal Value1 As Single, ByVal value2 As Single, ByVal value3 As Single) As Single
Return (Value1 * value2) / value3
End Function
Private Sub AddTextboxValues_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddTextboxValues.Click
Dim item1 As New ListViewItem(TextBox1.Text)
item1.SubItems.Add(TextBox2.Text)
ListView1.Items.AddRange(New ListViewItem() {item1})
End Sub
End Class