Solved

VB.Net MultiLine Text Boxes

Posted on 2016-08-26
3
75 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 500 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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 …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 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