?
Solved

VB.Net MultiLine Text Boxes

Posted on 2016-08-26
3
Medium Priority
?
78 Views
Last Modified: 2016-08-27
Here is my problem, i have a multi line Text Box and a List Box on my form.
The user can copy and paste a List of numbers in the multi line text Box.
When he clicks on Process i want to read line for line from text box and then
do some validation and if successful move the item to list box and remove from
text box.
I have my code who does the validation and putting int into the list box,, but having
issues with the removing from text box.

I tried to load the lines into a string list and then remove from string but problem
is that if i remove the item the list no longer has the same count as when i start and
the system will complain index out of range

Any ideas how to solve this cleanly ?
0
Comment
Question by:AlexPonnath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41772398
Can you show your code and how you manipulate the lines in the TextBox? Are you using the Lines collection?
0
 

Author Comment

by:AlexPonnath
ID: 41772458
If txtNumbers.Lines.Count > 0 Then
            Dim newList As List(Of String) = txtNumbers.Lines.ToList
            For i As Int32 = 0 To newList.Count - 1

                lbNumbers.Items.Add(AddPhoneFormat(newList.Item(i)))
                ' Remove the first line.  
                'newList.RemoveAt(i)

            Next
        End If

Open in new window

0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 41772561
Hi Alex;

Try this modified version of your code. It should do what you need.
If txtNumbers.Lines.Count > 0 Then
    Dim newList As List(Of String) = txtNumbers.Lines.ToList
    '' Access the newList in reverse order so that deleted items do not effect un-processed items
    '' by having its index changed and therefor changing all other item index
    For i As Int32 = newList.Count - 1 To 0 Step -1
        '' Because items are being inserted in reverse order use the Insert methods in place of
        '' The Add method and always Insert at index zero.
        lbNumbers.Items.Insert(0, newList.Item(i))
        'Remove the first line.  
        newList.RemoveAt(i)
    Next
    '' Now seeming you are working with a copy of the Items in the TextBox you need to place the 
    '' Items that were not removed back in the TextBox
    txtNumbers.Lines = newList.ToArray
End If

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question