Home All Groups Group Topic Archive Search About

listView - filling it with datareader

Author
10 Aug 2006 4:39 AM
Martin Panggabean
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("item1", 0)
    item1.SubItems.Add("1")
    item1.SubItems.Add("2")
    item1.SubItems.Add("3")
    Dim item2 As New ListViewItem("item2", 1)
    item2.SubItems.Add("4")
    item2.SubItems.Add("5")
    item2.SubItems.Add("6")
    Dim item3 As New ListViewItem("item3", 0)
    item3.SubItems.Add("7")
    item3.SubItems.Add("8")
    item3.SubItems.Add("9")

    ' Create columns for the items and subitems.
    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.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

Author
10 Aug 2006 5:14 AM
Cor Ligthert [MVP]
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

Show quoteHide quote
"Martin Panggabean" <martin.panggab***@jusufind.com> schreef in bericht
news:usz8JXDvGHA.1512@TK2MSFTNGP03.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("item1", 0)
>    item1.SubItems.Add("1")
>    item1.SubItems.Add("2")
>    item1.SubItems.Add("3")
>    Dim item2 As New ListViewItem("item2", 1)
>    item2.SubItems.Add("4")
>    item2.SubItems.Add("5")
>    item2.SubItems.Add("6")
>    Dim item3 As New ListViewItem("item3", 0)
>    item3.SubItems.Add("7")
>    item3.SubItems.Add("8")
>    item3.SubItems.Add("9")
>
>    ' Create columns for the items and subitems.
>    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
>    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
>    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
>    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.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
>
>
Author
14 Aug 2006 2:26 AM
Martin Panggabean
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

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:#NbktuDvGHA.4160@TK2MSFTNGP06.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***@jusufind.com> schreef in bericht
> news:usz8JXDvGHA.1512@TK2MSFTNGP03.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("item1", 0)
> >    item1.SubItems.Add("1")
> >    item1.SubItems.Add("2")
> >    item1.SubItems.Add("3")
> >    Dim item2 As New ListViewItem("item2", 1)
> >    item2.SubItems.Add("4")
> >    item2.SubItems.Add("5")
> >    item2.SubItems.Add("6")
> >    Dim item3 As New ListViewItem("item3", 0)
> >    item3.SubItems.Add("7")
> >    item3.SubItems.Add("8")
> >    item3.SubItems.Add("9")
> >
> >    ' Create columns for the items and subitems.
> >    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
> >    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
> >    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
> >    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.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
> >
> >
>
>
Author
14 Aug 2006 6:20 AM
Cor Ligthert [MVP]
Martin,

I have added two samples to our website.

http://www.vb-tips.com/dbpages.aspx?ID=60e4cbe5-1097-44d0-8560-a31addde6d2c

http://www.vb-tips.com/dbpages.aspx?ID=5910f96d-5e73-4910-88ba-2e3f12e1b3d7

I hope this helps,

Cor

Show quoteHide quote
"Martin Panggabean" <martin.panggab***@jusufind.com> schreef in bericht
news:ufdjbf0vGHA.4972@TK2MSFTNGP05.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]" <notmyfirstn***@planet.nl> wrote in message
> news:#NbktuDvGHA.4160@TK2MSFTNGP06.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***@jusufind.com> schreef in bericht
>> news:usz8JXDvGHA.1512@TK2MSFTNGP03.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("item1", 0)
>> >    item1.SubItems.Add("1")
>> >    item1.SubItems.Add("2")
>> >    item1.SubItems.Add("3")
>> >    Dim item2 As New ListViewItem("item2", 1)
>> >    item2.SubItems.Add("4")
>> >    item2.SubItems.Add("5")
>> >    item2.SubItems.Add("6")
>> >    Dim item3 As New ListViewItem("item3", 0)
>> >    item3.SubItems.Add("7")
>> >    item3.SubItems.Add("8")
>> >    item3.SubItems.Add("9")
>> >
>> >    ' Create columns for the items and subitems.
>> >    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
>> >    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
>> >    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
>> >    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.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
>> >
>> >
>>
>>
>
>