ListView add items, help.

  • Thread starter Thread starter musa.biralo
  • Start date Start date
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()
 
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
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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
 
Back
Top