selectitem from listview where number in column is smallest greater than zero

I need help using listview.

I have a listview with three columns

number, item, price

I need to get the cheapest price greater than zero then select item and number based on price

Can anyone help
thks
JasonAsked:
Who is Participating?
 
raysonleeCommented:
Not sure if this is what you are looking for:

        Dim db As New DataTable
        db.Columns.Add("Number", GetType(Integer))
        db.Columns.Add("Item")
        db.Columns.Add("Price", GetType(Decimal))
        db.Rows.Add("1", "Item 1", "10.00")
        db.Rows.Add("2", "Item 2", "5.00")
        db.Rows.Add("3", "Item 3", "-5.00")
        ListView1.View = View.Details
        ListView1.Columns.Add("Number", 100, HorizontalAlignment.Left)
        ListView1.Columns.Add("Item", 150, HorizontalAlignment.Left)
        ListView1.Columns.Add("Price", 100, HorizontalAlignment.Right)
        Dim lsi As ListViewItem
        For i As Integer = 0 To 2
            lsi = New ListViewItem(db.Rows(i).Item("Number").ToString)
            lsi.SubItems.Add(db.Rows(i).Item("Item").ToString)
            lsi.SubItems.Add(db.Rows(i).Item("Price").ToString)
            ListView1.Items.Add(lsi)
        Next
        Dim lplvi As ListViewItem = ListView1.Items(0)
        For Each lvi As ListViewItem In ListView1.Items
            If CType(lvi.SubItems(2).Text, Decimal) > 0 Then
                If CType(lvi.SubItems(2).Text, Decimal) < CType(lplvi.SubItems(2).Text, Decimal) Then
                    lplvi = lvi
                End If
            End If
        Next
        Dim number As Integer = CType(lplvi.Text, Integer)
        Dim item As String = lplvi.SubItems(1).Text.ToString
        MsgBox("Item with lowest price is: " & number.ToString & " " & item)

If you want to implement a column sorter instead, you can refer to http://www.akadia.com/services/dotnet_listview_sort_dataset.html
0
 
himanshutCommented:
your query should be something like:

select * from tblname order by price asc

the first record will have the item and number along with the cheapest price which you can play with.

Hope that helps!
0
 
JasonAuthor Commented:
can this be done with listview???????
0
 
JasonAuthor Commented:
Legend thanks for your help Works great
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.