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

Posted on 2011-10-16
Last Modified: 2012-05-12
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
Question by:Jason
    LVL 10

    Expert Comment

    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!

    Author Comment

    can this be done with listview???????
    LVL 9

    Accepted Solution

    Not sure if this is what you are looking for:

            Dim db As New DataTable
            db.Columns.Add("Number", GetType(Integer))
            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)
            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
            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

    Author Closing Comment

    Legend thanks for your help Works great

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    I'm currently working for a company where I have to upgrade over 50 VB6 programs to VB.NET 2008.  So far I'm about half way through, and I've learned quite a few tricks that drastically improve the performance of VB.NET apps. Because there are a…
    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now