listView - filling it with datareader

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Panggabean

    #1

    listView - filling it with datareader

    Hello All,

    I've kind a logic problem ... I want to fill the listView control in VB.NET
    with data in my mySql table using Datareader object component. But It seems
    that the way of how listView being used is quite different from usual
    column-row component like Grid component. If you kind a familiar using
    listView, u must have known what i'm talking about. Here is some example i
    took from MSDN :
    ----------------------------------------------------------------------------
    ---------
    Dim item1 As New ListViewItem("i tem1", 0)
    item1.SubItems. Add("1")
    item1.SubItems. Add("2")
    item1.SubItems. Add("3")
    Dim item2 As New ListViewItem("i tem2", 1)
    item2.SubItems. Add("4")
    item2.SubItems. Add("5")
    item2.SubItems. Add("6")
    Dim item3 As New ListViewItem("i tem3", 0)
    item3.SubItems. Add("7")
    item3.SubItems. Add("8")
    item3.SubItems. Add("9")

    ' Create columns for the items and subitems.
    listView1.Colum ns.Add("Item Column", -2, HorizontalAlign ment.Left)
    listView1.Colum ns.Add("Column 2", -2, HorizontalAlign ment.Left)
    listView1.Colum ns.Add("Column 3", -2, HorizontalAlign ment.Left)
    listView1.Colum ns.Add("Column 4", -2, HorizontalAlign ment.Center)

    'Add the items to the ListView.
    listView1.Items .AddRange(New ListViewItem() {item1, item2, item3})
    ----------------------------------------------------------------------------
    -----------
    the result on listView control :
    ------------------------------------------------------
    Item Columnt | Column 2 | Column 3 | Column 4
    ------------------------------------------------------
    Item1 1 2 3
    Item2 4 5 6
    Item3 7 8 9


    the problem is that I want to fill the listView control by using While
    looping ....

    While dr.read() ---- datareader component containing 4 columns and many rows
    of data

    ..... fill the listView

    End While

    If only I know and it possible to define the item object inside the loop it
    might solve the problem ..... or maybe you guys have a different logic to
    solve this, i would appreciate it much

    Thx
    Martin
    - newbie in VB.Net


  • Cor Ligthert [MVP]

    #2
    Re: listView - filling it with datareader

    Martin,

    What is the problem, the only thing you have to check in your loop is if the
    level of your rows changes (and therefore a new item from a higher level be
    added). Something that should be basic for every developer.

    Cor

    "Martin Panggabean" <martin.panggab ean@jusufind.co mschreef in bericht
    news:usz8JXDvGH A.1512@TK2MSFTN GP03.phx.gbl...
    Hello All,
    >
    I've kind a logic problem ... I want to fill the listView control in
    VB.NET
    with data in my mySql table using Datareader object component. But It
    seems
    that the way of how listView being used is quite different from usual
    column-row component like Grid component. If you kind a familiar using
    listView, u must have known what i'm talking about. Here is some example i
    took from MSDN :
    ----------------------------------------------------------------------------
    ---------
    Dim item1 As New ListViewItem("i tem1", 0)
    item1.SubItems. Add("1")
    item1.SubItems. Add("2")
    item1.SubItems. Add("3")
    Dim item2 As New ListViewItem("i tem2", 1)
    item2.SubItems. Add("4")
    item2.SubItems. Add("5")
    item2.SubItems. Add("6")
    Dim item3 As New ListViewItem("i tem3", 0)
    item3.SubItems. Add("7")
    item3.SubItems. Add("8")
    item3.SubItems. Add("9")
    >
    ' Create columns for the items and subitems.
    listView1.Colum ns.Add("Item Column", -2, HorizontalAlign ment.Left)
    listView1.Colum ns.Add("Column 2", -2, HorizontalAlign ment.Left)
    listView1.Colum ns.Add("Column 3", -2, HorizontalAlign ment.Left)
    listView1.Colum ns.Add("Column 4", -2, HorizontalAlign ment.Center)
    >
    'Add the items to the ListView.
    listView1.Items .AddRange(New ListViewItem() {item1, item2, item3})
    ----------------------------------------------------------------------------
    -----------
    the result on listView control :
    ------------------------------------------------------
    Item Columnt | Column 2 | Column 3 | Column 4
    ------------------------------------------------------
    Item1 1 2 3
    Item2 4 5 6
    Item3 7 8 9
    >
    >
    the problem is that I want to fill the listView control by using While
    looping ....
    >
    While dr.read() ---- datareader component containing 4 columns and many
    rows
    of data
    >
    ..... fill the listView
    >
    End While
    >
    If only I know and it possible to define the item object inside the loop
    it
    might solve the problem ..... or maybe you guys have a different logic to
    solve this, i would appreciate it much
    >
    Thx
    Martin
    - newbie in VB.Net
    >
    >

    Comment

    • Martin Panggabean

      #3
      Re: listView - filling it with datareader

      Yes, you're right. I gotta do something inside the loop. But, in vb.net ...
      i don't know how to create new subitems inside the loop ...

      Sorry ... im a newbie ....

      BR,

      Martin

      "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
      news:#NbktuDvGH A.4160@TK2MSFTN GP06.phx.gbl...
      Martin,
      >
      What is the problem, the only thing you have to check in your loop is if
      the
      level of your rows changes (and therefore a new item from a higher level
      be
      added). Something that should be basic for every developer.
      >
      Cor
      >
      "Martin Panggabean" <martin.panggab ean@jusufind.co mschreef in bericht
      news:usz8JXDvGH A.1512@TK2MSFTN GP03.phx.gbl...
      Hello All,

      I've kind a logic problem ... I want to fill the listView control in
      VB.NET
      with data in my mySql table using Datareader object component. But It
      seems
      that the way of how listView being used is quite different from usual
      column-row component like Grid component. If you kind a familiar using
      listView, u must have known what i'm talking about. Here is some example
      i
      took from MSDN :
      >
      --------------------------------------------------------------------------
      --
      ---------
      Dim item1 As New ListViewItem("i tem1", 0)
      item1.SubItems. Add("1")
      item1.SubItems. Add("2")
      item1.SubItems. Add("3")
      Dim item2 As New ListViewItem("i tem2", 1)
      item2.SubItems. Add("4")
      item2.SubItems. Add("5")
      item2.SubItems. Add("6")
      Dim item3 As New ListViewItem("i tem3", 0)
      item3.SubItems. Add("7")
      item3.SubItems. Add("8")
      item3.SubItems. Add("9")

      ' Create columns for the items and subitems.
      listView1.Colum ns.Add("Item Column", -2, HorizontalAlign ment.Left)
      listView1.Colum ns.Add("Column 2", -2, HorizontalAlign ment.Left)
      listView1.Colum ns.Add("Column 3", -2, HorizontalAlign ment.Left)
      listView1.Colum ns.Add("Column 4", -2, HorizontalAlign ment.Center)

      'Add the items to the ListView.
      listView1.Items .AddRange(New ListViewItem() {item1, item2, item3})
      >
      --------------------------------------------------------------------------
      --
      -----------
      the result on listView control :
      ------------------------------------------------------
      Item Columnt | Column 2 | Column 3 | Column 4
      ------------------------------------------------------
      Item1 1 2 3
      Item2 4 5 6
      Item3 7 8 9


      the problem is that I want to fill the listView control by using While
      looping ....

      While dr.read() ---- datareader component containing 4 columns and many
      rows
      of data

      ..... fill the listView

      End While

      If only I know and it possible to define the item object inside the loop
      it
      might solve the problem ..... or maybe you guys have a different logic
      to
      solve this, i would appreciate it much

      Thx
      Martin
      - newbie in VB.Net
      >
      >

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: listView - filling it with datareader

        Martin,

        I have added two samples to our website.





        I hope this helps,

        Cor

        "Martin Panggabean" <martin.panggab ean@jusufind.co mschreef in bericht
        news:ufdjbf0vGH A.4972@TK2MSFTN GP05.phx.gbl...
        Yes, you're right. I gotta do something inside the loop. But, in vb.net
        ...
        i don't know how to create new subitems inside the loop ...
        >
        Sorry ... im a newbie ....
        >
        BR,
        >
        Martin
        >
        "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
        news:#NbktuDvGH A.4160@TK2MSFTN GP06.phx.gbl...
        >Martin,
        >>
        >What is the problem, the only thing you have to check in your loop is if
        the
        >level of your rows changes (and therefore a new item from a higher level
        be
        >added). Something that should be basic for every developer.
        >>
        >Cor
        >>
        >"Martin Panggabean" <martin.panggab ean@jusufind.co mschreef in bericht
        >news:usz8JXDvG HA.1512@TK2MSFT NGP03.phx.gbl.. .
        Hello All,
        >
        I've kind a logic problem ... I want to fill the listView control in
        VB.NET
        with data in my mySql table using Datareader object component. But It
        seems
        that the way of how listView being used is quite different from usual
        column-row component like Grid component. If you kind a familiar using
        listView, u must have known what i'm talking about. Here is some
        example
        i
        took from MSDN :
        >>
        >--------------------------------------------------------------------------
        --
        ---------
        Dim item1 As New ListViewItem("i tem1", 0)
        item1.SubItems. Add("1")
        item1.SubItems. Add("2")
        item1.SubItems. Add("3")
        Dim item2 As New ListViewItem("i tem2", 1)
        item2.SubItems. Add("4")
        item2.SubItems. Add("5")
        item2.SubItems. Add("6")
        Dim item3 As New ListViewItem("i tem3", 0)
        item3.SubItems. Add("7")
        item3.SubItems. Add("8")
        item3.SubItems. Add("9")
        >
        ' Create columns for the items and subitems.
        listView1.Colum ns.Add("Item Column", -2, HorizontalAlign ment.Left)
        listView1.Colum ns.Add("Column 2", -2, HorizontalAlign ment.Left)
        listView1.Colum ns.Add("Column 3", -2, HorizontalAlign ment.Left)
        listView1.Colum ns.Add("Column 4", -2, HorizontalAlign ment.Center)
        >
        'Add the items to the ListView.
        listView1.Items .AddRange(New ListViewItem() {item1, item2, item3})
        >>
        >--------------------------------------------------------------------------
        --
        -----------
        the result on listView control :
        ------------------------------------------------------
        Item Columnt | Column 2 | Column 3 | Column 4
        ------------------------------------------------------
        Item1 1 2 3
        Item2 4 5 6
        Item3 7 8 9
        >
        >
        the problem is that I want to fill the listView control by using While
        looping ....
        >
        While dr.read() ---- datareader component containing 4 columns and many
        rows
        of data
        >
        ..... fill the listView
        >
        End While
        >
        If only I know and it possible to define the item object inside the
        loop
        it
        might solve the problem ..... or maybe you guys have a different logic
        to
        solve this, i would appreciate it much
        >
        Thx
        Martin
        - newbie in VB.Net
        >
        >
        >>
        >>
        >
        >

        Comment

        Working...