Resolved Textbox Multiple Lines to Listview

zackmark29

Active member
Joined
Apr 21, 2020
Messages
28
Programming Experience
Beginner
Hi I'm trying to adding multiple lines from textbox
But I can't fix this little error

VB.NET:
Dim ID = txtID.Lines
        Dim Title = txtTitle.Lines
        Dim Date2 = txtDate.Lines
        Dim url = txtOutput.Lines
        Dim items As New List(Of ListViewItem)

        For I = 0 To Math.Min(ID.GetUpperBound(0), Title.GetUpperBound(0), Date2.GetUpperBound(0), url.GetUpperBound(0))
            items.Add(New ListViewItem({ID(I), Title(I), Date2(I), url(I)}))
        Next
        ListView1.Items.AddRange(items.ToArray())

Here's the error

Overload resolution failed because no accessible 'Min' accepts this number of arguments
 
That should come as no surprise to you since documentation for that method says:
Returns the smaller of two numbers.

To get the minimum of a collection of numbers you can use the Linq extension method Min:
In code you can collect the values in an array and use that as source:
VB.NET:
Dim upper = {ID.GetUpperBound(0), Title.GetUpperBound(0), Date2.GetUpperBound(0), url.GetUpperBound(0)}
For I = 0 To upper.Min
 
It worked :) Problem solved

Here's the fixed code

VB.NET:
        Dim ID = txtID.Lines
        Dim Title = txtTitle.Lines
        Dim Date2 = txtDate.Lines
        Dim url = txtOutput.Lines
        Dim items As New List(Of ListViewItem)

        Dim upper = {ID.GetUpperBound(0), Title.GetUpperBound(0), Date2.GetUpperBound(0), url.GetUpperBound(0)}
        For I = 0 To upper.Min
            items.Add(New ListViewItem({ID(I), Title(I), Date2(I), url(I)}))
        Next

ListView1.Items.AddRange(items.ToArray())
 

Latest posts

Back
Top