i have 6 collumn in a listview , how do i multiply each data by row in collumn 4 and 5 and display the result in collumn 6.??

Inline Code Example Here

Dim itm As ListViewItem
str(0) = txttarikh.Text
str(1) = txtresit.Text
str(2) = Txtkod.Text
str(3) = Txtnama.Text
str(4) = Txtharga.Text
str(5) = txtkuantiti.Text
str(6) =
itm = New ListViewItem(str)

## All 2 Replies

A ListView (in details view) consists of a collection of items (or rows) where each item contains subitems (or columns). In the following example I have defined ListView1 as containing 6 columns. If I add some sample data as follows

For row As Integer = 1 To 6
Dim newitem As New ListViewItem(CStr(row))
For col As Integer = 1 To 5
Next
Next

The next code block multiplies column 4 by column 5 and places the result in column 6 (because subitems are zero relative the calculation is actually col5 = col3 * col4)

For Each row As ListViewItem In ListView1.Items
Dim arg1 As Integer = CInt(row.SubItems(3).Text)
Dim arg2 As Integer = CInt(row.SubItems(4).Text)
row.SubItems(5).Text = CStr(arg1 * arg2)
Next

However, you may not already have data in the last column. In the following code I am only going to add data in the first 5 columns. In that case, the calculation will have to add a new subitem to store the results.

For row As Integer = 1 To 6
Dim newitem As New ListViewItem(CStr(row))
For col As Integer = 1 To 4
Next
Next

For Each row As ListViewItem In ListView1.Items
Dim arg1 As Integer = CInt(row.SubItems(3).Text)
Dim arg2 As Integer = CInt(row.SubItems(4).Text)