By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,903 Members | 1,973 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,903 IT Pros & Developers. It's quick & easy.

listView - filling it with datareader

P: n/a
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
Aug 10 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <ma***************@jusufind.comschreef in bericht
news:us**************@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


Aug 10 '06 #2

P: n/a
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]" <no************@planet.nlwrote in message
news:#N**************@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" <ma***************@jusufind.comschreef in bericht
news:us**************@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


Aug 14 '06 #3

P: n/a
Martin,

I have added two samples to our website.

http://www.vb-tips.com/dbpages.aspx?...0-a31addde6d2c

http://www.vb-tips.com/dbpages.aspx?...a-2e3f12e1b3d7

I hope this helps,

Cor

"Martin Panggabean" <ma***************@jusufind.comschreef in bericht
news:uf**************@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]" <no************@planet.nlwrote in message
news:#N**************@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" <ma***************@jusufind.comschreef in bericht
news:us**************@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




Aug 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.