ListView add items, help.

M

musa.biralo

Hi there,

Knowing little is the worst thing :(. I am having trouble with this
code... I am beginner and this is not working for me at all...

I am simply trying to list my listview. I tried googling hours but end
up here.. .Please help... My listview is in detail mode. When i run
the following code, the listview becomes longer (vertical scroll pops
up) but there is nothing in the list, neither does the column header
shows up... :(

Dim userListView As ListView = Me.listViewUN
userListView.BeginUpdate()
userListView.Items.Clear()


For i As Integer = 0 To 9

Dim lvi As ListViewItem = userListView.Items.Add
(i.ToString)

lvi.Text = "Row " & i.ToString
lvi.SubItems.Add(CStr(i + 10))
lvi.SubItems.Add(CStr(i + 20))
lvi.SubItems.Add(CStr(i + 30))
lvi.SubItems.Add(CStr(i + 10))
lvi.SubItems.Add(CStr(i + 20))

''''Me.userListView.Items.Add(lvi)
Next i

userListView.Columns.Add("aaa")
userListView.Columns.Add("bbb")
userListView.Columns.Add("ccc")
userListView.Columns.Add("ddd")
userListView.Columns.Add("eeee")

userListView.EndUpdate()
 
C

Cor Ligthert[MVP]

Hi,

We don't know what listViewUN is,

But your definitely needs
\\\
Controls.Add(userListView)
///
And as that is not in listViewUN probably (I don't know the style you want)
\\\
userListView.View = View.Details
///

I hope this helps,

Cor
 
M

musa.biralo

Thanks for the reply, Cor.

userListViewUN is just a ListView in a form and is in View.Details
style as you mentioned. I added the "Controls.Add(userListView)" right
before the userListView.EndUpdate(). However, i am still not able to
see things in the ListView. It appears as things are there but nothing
is showing up as the ListView vertical scroll pops up and you can
scroll up and down...

Any further suggestion?

Musa.
 
C

Cor Ligthert[MVP]

Musa.

I had tried your code with these simple changes

And it did work

\\\
Dim userListView As New ListView
Controls.Add(userListView)
userListView.View = View.Details
userListView.BeginUpdate()
userListView.Items.Clear()
For i As Integer = 0 To 9
Dim lvi As ListViewItem = userListView.Items.Add(i.ToString)
lvi.Text = "Row " & i.ToString
lvi.SubItems.Add(CStr(i + 10))
lvi.SubItems.Add(CStr(i + 20))
lvi.SubItems.Add(CStr(i + 30))
lvi.SubItems.Add(CStr(i + 10))
lvi.SubItems.Add(CStr(i + 20))
''''Me.userListView.Items.Add(lvi)
Next i
userListView.Columns.Add("aaa")
userListView.Columns.Add("bbb")
userListView.Columns.Add("ccc")
userListView.Columns.Add("ddd")
userListView.Columns.Add("eeee")
userListView.EndUpdate()
///

All changes are in the first 3 rows

I hope this helps,

Cor

Thanks for the reply, Cor.

userListViewUN is just a ListView in a form and is in View.Details
style as you mentioned. I added the "Controls.Add(userListView)" right
before the userListView.EndUpdate(). However, i am still not able to
see things in the ListView. It appears as things are there but nothing
is showing up as the ListView vertical scroll pops up and you can
scroll up and down...

Any further suggestion?

Musa.
 
B

Branco

Cor Ligthert[MVP] wrote:
We don't know what listViewUN is,

But your definitely needs
\\\
Controls.Add(userListView)
///
And as that is not in listViewUN probably (I don't know the style you want)
\\\
userListView.View = View.Details
///
<snip>

It is necessary to say that the line "Controls.Add(..." is not
necessary if the listview is already in the form. The same goes for
setting it to View.Details if it already is in details view.

Regards,

Branco.
 
M

musa.biralo

Thanks Cor, that was helpful!

It helped me to narrow down the problem. What i found is little
surprising (may be for this newbie).

When i use "Dim userListView As New ListView", a new ListView shows up
in the Form and things are populated as expected.

When i use Dim userListView As ListView = Me.listViewUN, thing are
not showing up. As i said, you can see the Vscroll but no data in the
ListView. So, i added useListView.Update() but no luck :( (What i am
trying is to populate the ListViwUN which is in my form)


Any thoughts, suggestion?
Really appreciate your help.

Musa.
 
B

Branco

musa.biralo wrote:
I am simply trying to list my listview. I tried googling hours but end
up here.. .Please help... My listview is in detail mode. When i run
the following code, the listview becomes longer (vertical scroll pops
up) but there is nothing in the list, neither does the column header
shows up... :(
<snip>

Note that if the ListView is in OwnerDraw mode it won't show any items
(unless you put code to respond to the drawing events).

HTH.

Regards,

Branco.
 
M

musa.biralo

You found it!!!

When i changed the "Owner Draw" to "False", Everything was as
expected.

Thanks for helping me. A little apprication of 5 stars for you. I
hope you will like it. :)

Thanks again.
Musa.
 
M

musa.biralo

I must thank Cor as well.

Cor, Thank You !!!

You found it!!!

When i changed the "Owner Draw" to "False", Everything was as
expected.

Thanks for helping me.  A little apprication of 5 stars for you. I
hope you will like it. :)

Thanks again.
Musa.
 
C

Cor Ligthert[MVP]

Branc,

You are right, I was simply assuming that it was new........

Now it is used as a kind of delegating the listview with a new name.

I never do that,

:)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top