Hi all...

I'm new in vb.net and just create a listview project . I wan to display item from database(.mdb) into listview.how to make the next item going below and not auto sorting by id?...please help me...thank in advance

 Do While IBSSDR.Read()



            If IBSSDR.Item("USERDEFINED10").Equals("Y") Then

                ListView1.Items.Add(IBSSDR.Item("CARDHOLDERID")).ToString()
                ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(IBSSDR.Item("NAME")).ToString()



                If IBSSDR.Item("CARDID") Is DBNull.Value Then
                    ListView1.Items(ListView1.Items.Count - 1).SubItems.Add("").ToString()
                Else
                    ListView1.Items(ListView1.Items.Count 1).SubItems.Add(IBSSDR.Item("CARDID")).ToString()

                End If


            End If

        Loop

ibssdr.close

if you're planning to put an item to your Listview

try this code if would help

While datareader.read

Dim listview as new ListviewItem

with listview

.text = datareader.item("database columnName") 'This is your 1st listview column
.subitems.add(datareader.item("database columnName")) 'your 2nd listview column
.subitems.add(datareader.item("database columnName")) 'your 3rd listview column

 end with

Listview1.items.add(listview)

End While

Please marked solved if it helps...

tq for idea. Actually i'm using datareader ( IBSSDR.READ)but unfortunately when there got new record, it will automaticly sort sequencely by id....what i need to do is the new item have to display below new line...please help me...tq

Can you show me your code so that I could analyze it.

       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim IBSSDB As String = "User= " & TextBox1.Text.ToString & ";" + "Password=" & TextBox2.Text.ToString & ";" + "Database=" & TextBox3.Text.ToString & ";" + "DataSource=" & TextBox4.Text.ToString & ";" + "Port=3050;" + "Dialect=3;" + "Charset=NONE;" + "Role=;" + "Connection lifetime=15;" + "Pooling=true;" + "MinPoolSize=0;" + "MaxPoolSize=50;" + "Packet Size=8192;" + "ServerType=0;"
        Dim IBSSUMP As New FbConnection(IBSSDB)
        Dim IBSSCMD As New FbCommand



        IBSSCMD = New FbCommand("select  * from CARDHOLDER  ", IBSSUMP)
        IBSSUMP.Open()
        IBSSDR = IBSSCMD.ExecuteReader()

        '***********************************************************
        'START CHECKING DATA
        '###########################################################





        ListView1.Items.Clear()


        ' ListView1.Refresh()

        Dim bFlag As Boolean = True
        Do Until Not bFlag



            While IBSSDR.Read()



                If IBSSDR.Item("USERDEFINED10").Equals("Y") Then

                    ListView1.Items.Add(IBSSDR.Item("CARDHOLDERID")).ToString()
                    ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(IBSSDR.Item("NAME")).ToString()



                     If IBSSDR.Item("CARDID") Is DBNull.Value Then
                    ListView1.Items(ListView1.Items.Count - 1).SubItems.Add("").ToString()
                     Else
                         ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(IBSSDR.Item("CARDID")).ToString()

                       End If









                End If

            End While
            'CHECK FOR NEXT STAFF
            bFlag = IBSSDR.NextResult()


        Loop
        IBSSDR.Dispose()

        IBSSUMP.Close()





    End Sub

Here the code...hope you can help me....What i need is when got any change for the data....the new item will be display in listview below the current item....but right now it will display accordingly follow the Cardholderid numbering....lease help me...tq in advance

Hi kerek,

at first I thought that you are using some kind of a ORDER statement in your SELECT QUERY but you didn't.

that's why I suggest you to try the following.

Ussumming that you already populated your Listview with the data from the Database
and look like this.

CardHolderID           FirstName                LastName

     3                   John                    Smith
     1                   Luke                    Noorwood
     4                   Sean                    Milke

In your Listview you already have 3 record that are populated from the database.

1.) Right after your INSERT statemet to the database I want you to add the following code.

Dim MyListview as new ListviewItem

With MyListview

.Text = "10"          =====> 'what ever you are trying to INSERT in the database
.Subitems.add("Matt")   =====> 'if you are getting the data in the textbox
.Subitems.add("Damon")   =====> 'try .Subitems.add(Textbox1.text)


End With

Listview1.items.add(MyListview)

And your listview will now look like this.

CardHolderID           FirstName                LastName

     3                   John                    Smith
     1                   Luke                    Noorwood
     4                   Sean                    Milke
    10                   Matt                    Damon

Hope this solves your porblem.

Thank you very2 much...you're the great...already done.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.