• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

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
0
Jason
Asked:
Jason
  • 2
1 Solution
 
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
 
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
 
JasonAuthor Commented:
Legend thanks for your help Works great
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now