Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27248

Multiple listviews, messy code

$
0
0
Ladies & Gents,

I have a number of listviews setup in my application. The variable 'tableno' is already set elsewhere as a string value between 1 & 6 and the following code works when I want to move all listview1 items into a specific tablelist listview.
Code:

                  For Each itm In ListView1.Items
                      Dim newItm As ListViewItem = itm.Clone
                        Select Case tableno
                            Case "1"
                                tablelist1.Items.Add(newItm)
                            Case "2"
                                tablelist2.Items.Add(newItm)
                            Case "3"
                                tablelist3.Items.Add(newItm)
                            Case "4"
                                tablelist4.Items.Add(newItm)
                            Case "5"
                                tablelist5.Items.Add(newItm)
                            Case "6"
                                tablelist6.Items.Add(newItm)
                        End Select
                    Next

I tried to tidy the code up with this:
Code:

For Each itm In ListView1.Items
  Dim newItm As ListViewItem = itm.Clone
Controls("tablelist" + tableno).items.add(newItm)
Next

But I get the error: 'items' is not a member of 'System.Windows.Forms.Control'

I'm sure there must be a way to tidy the code up so, please, what am I doing wrong?

Thanks

John

Viewing all articles
Browse latest Browse all 27248

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>