Results 1 to 8 of 8

Thread: delete lines in multiply textboxes and a universal scroll bar for listboxes in vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2015
    Posts
    10

    delete lines in multiply textboxes and a universal scroll bar for listboxes in vb.net

    so this is a 2 parter

    1i have 6 text boxes all multi line. i need code that will go through all the numbers in text box 3 and then delete any number over 2, then remove that corresponding line from the 5 other text boxes

    2i also have 6 list boxes, when i scroll in 1 i want them all to scroll. i know there is an option for columns, but this is not what i am looking for.

    any help would be great as i am lost

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: delete lines in multiply textboxes and a universal scroll bar for listboxes in vb

    Syncronizing listboxes is a pain in the neck. There's not much reason to do that, normally, because if you have 6 columns, each with N rows, such that row 1 in listbox 1 associates with row 1 in all five of the other listboxes, then you might as well just use either a Listview in Detail mode, or a DataGridView.
    My usual boring signature: Nothing

  3. #3
    Hyperactive Member Vexslasher's Avatar
    Join Date
    Feb 2010
    Posts
    429

    Re: delete lines in multiply textboxes and a universal scroll bar for listboxes in vb

    1. This will remove all the items with numbers larger then 2 from textbox3 and will remove the corresponding lines from the other 5 textboxes.
    Better Code in my post 8 here
    vb.net Code:
    1. Sub Other5()
    2.         Dim Cur As Integer = 5
    3.         Dim TB As TextBox = TextBox6
    4.         Dim TB1Lines As New List(Of String)(TextBox1.Lines)
    5.         Dim TB2Lines As New List(Of String)(TextBox2.Lines)
    6.         Dim TB4Lines As New List(Of String)(TextBox4.Lines)
    7.         Dim TB5Lines As New List(Of String)(TextBox5.Lines)
    8.         Dim TB6Lines As New List(Of String)(TextBox6.Lines)
    9.         Dim Lines As New List(Of String)
    10.         For a = 1 To 5
    11.             If Cur = 1 Then
    12.                 Lines = TB1Lines
    13.                 TB = TextBox1
    14.             ElseIf Cur = 2 Then
    15.                 Lines = TB2Lines
    16.                 TB = TextBox2
    17.             ElseIf Cur = 3 Then
    18.                 Lines = TB4Lines
    19.                 TB = TextBox4
    20.             ElseIf Cur = 4 Then
    21.                 Lines = TB5Lines
    22.                 TB = TextBox5
    23.             ElseIf Cur = 5 Then
    24.                 Lines = TB6Lines
    25.                 TB = TextBox6
    26.             End If
    27.             If Cur = 0 = False Then
    28.                 For x As Integer = Lines.Count - 1 To 0 Step -1
    29.                     If Lines(x).ToString.Length > 0 Then
    30.                         If CInt(Lines(x).ToString) > 2 = True Then
    31.                             Lines.Remove(Lines(x).ToString)
    32.                         End If
    33.                     End If
    34.                 Next
    35.                 Cur = Cur - 1
    36.             End If
    37.             TB.Lines = Lines.ToArray
    38.         Next
    39.  
    40.     End Sub
    41.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    42.         Dim Lines As New List(Of String)(TextBox3.Lines)
    43.         For x As Integer = Lines.Count - 1 To 0 Step -1
    44.             If Lines(x).ToString.Length > 0 Then
    45.                 If CInt(Lines(x).ToString) > 2 = True Then
    46.                     'removes all the lines that were removed from textbox3
    47.                     Call Other5()
    48.                     'removes the items from textbox3
    49.                     Lines.Remove(Lines(x).ToString)
    50.                 End If
    51.             End If
    52.         Next
    53.         TextBox3.Lines = Lines.ToArray
    54.     End Sub

    2. You have to pretty much make a new type of listbox for this or just use a listview instead here is an example of how to do this making the new listbox check the 3rd post.
    Last edited by Vexslasher; May 23rd, 2016 at 01:24 PM.

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2015
    Posts
    10

    Re: delete lines in multiply textboxes and a universal scroll bar for listboxes in vb

    thanks for the reply

    i have swtched the list view to datagrid so that solved one issue.
    sadly the code didnt work think it is because the numbers are to 2 decimal places 1.87 2.36 8.59, any ideas on how to fix?

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2015
    Posts
    10

    Re: delete lines in multiply textboxes and a universal scroll bar for listboxes in vb

    this is my new code but will not work on every number, not sure where it is going wrong
    vb.net Code:
    1. Dim list1 As List(Of String) = TextBox1.Lines.ToList
    2.         Dim list2 As List(Of String) = TextBox2.Lines.ToList
    3.         Dim list3 As List(Of String) = TextBox3.Lines.ToList
    4.         Dim list4 As List(Of String) = TextBox4.Lines.ToList
    5.         Dim list5 As List(Of String) = TextBox5.Lines.ToList
    6.         Dim list6 As List(Of String) = TextBox6.Lines.ToList
    7.         Dim t As Int32
    8.         Dim lin As String
    9.  
    10.         t = 1
    11.         lin = TextBox4.Lines(t).ToString()
    12.  
    13.         Do Until t = TextBox4.Lines.Count
    14.  
    15.             If lin > 2 Then
    16.  
    17.  
    18.                 list1.RemoveAt(t)
    19.                 TextBox1.Lines = list1.ToArray
    20.                 list2.RemoveAt(t)
    21.                 TextBox2.Lines = list2.ToArray
    22.                 list3.RemoveAt(t)
    23.                 TextBox3.Lines = list3.ToArray
    24.                 list5.RemoveAt(t)
    25.                 TextBox5.Lines = list5.ToArray
    26.                 list6.RemoveAt(t)
    27.                 TextBox6.Lines = list6.ToArray
    28.                 list4.RemoveAt(t)
    29.                 TextBox4.Lines = list4.ToArray
    30.  
    31.                 t += 1
    32.  
    33.             End If
    34.  
    35.         Loop
    Last edited by FunkyDexter; May 23rd, 2016 at 04:30 AM. Reason: Added code tags

  6. #6
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: delete lines in multiply textboxes and a universal scroll bar for listboxes in vb

    deephect, I've added highlight tags to your code to get it to display nicely. You can do this yourself when posting code by hitting either the VB or # button. The former will add highlight tags for which you can specify the language (vb, vb.net, c# etc.), that latter will add more generic Code tags.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: delete lines in multiply textboxes and a universal scroll bar for listboxes in vb

    I don't understand the question. Numbers are numbers, and they don't have a number of decimal places. A string representation of a number can have a number of decimal places, but you can always adjust that. So, in post #4, you'd have to explain a bit more to say why the code wouldn't work due to the number of decimal places, since that isn't a real issue. As for post #5, what do you mean when you say that "it won't work on every number"? There are no numbers evident in that code.
    My usual boring signature: Nothing

  8. #8
    Hyperactive Member Vexslasher's Avatar
    Join Date
    Feb 2010
    Posts
    429

    Re: delete lines in multiply textboxes and a universal scroll bar for listboxes in vb

    That code you provided just freezes the form for me. I only could spot one thing wrong with it but it doesn't fix it. The problem I spotted is on line 15 that needs to be either.
    Code:
    If CInt(lin) > 2 Then
    or
    Code:
    If Convert.toInt32(lin) > 2 Then
    but if your using decimals it would be
    Code:
    If Convert.ToDecimal(lin) > 2 Then
    I'm not sure what the values of your numbers are so it's impossible to provide the exact answer without knowing what those values can be but hopefully this will help you in resolving your problem.


    I also made a better code for you to use. I noticed your using the textbox4 instead of the textbox3 so this will remove all the items with numbers larger then 2 from textbox4 and then will remove the corresponding lines from the other 5 textboxes. (My older code before was pretty much just running the same code over all the textboxes but it looks like your needing something more like this.)
    vb.net Code:
    1. Dim TB1Lines As New List(Of String)(TextBox1.Lines)
    2.         Dim TB2Lines As New List(Of String)(TextBox2.Lines)
    3.         Dim TB3Lines As New List(Of String)(TextBox3.Lines)
    4.         Dim TB5Lines As New List(Of String)(TextBox5.Lines)
    5.         Dim TB6Lines As New List(Of String)(TextBox6.Lines)
    6.         Dim Lines As New List(Of String)(TextBox4.Lines)
    7.             For x As Integer = Lines.Count - 1 To 0 Step -1
    8.                 If Lines(x).ToString.Length > 0 Then
    9.                     If CInt(Lines(x).ToString) > 2 = True Then
    10.                     TB1Lines.Remove(TB1Lines(x).ToString)
    11.                     TB2Lines.Remove(TB2Lines(x).ToString)
    12.                     TB3Lines.Remove(TB3Lines(x).ToString)
    13.                     TB5Lines.Remove(TB5Lines(x).ToString)
    14.                     TB6Lines.Remove(TB6Lines(x).ToString)
    15.                     Lines.Remove(Lines(x).ToString)
    16.                         TextBox1.Lines = TB1Lines.ToArray
    17.                         TextBox2.Lines = TB2Lines.ToArray
    18.                         TextBox3.Lines = TB3Lines.ToArray
    19.                         TextBox5.Lines = TB5Lines.ToArray
    20.                         TextBox6.Lines = TB6Lines.ToArray
    21.                         TextBox4.Lines = Lines.ToArray
    22.                     End If
    23.                 End If
    24.             Next
    Last edited by Vexslasher; May 23rd, 2016 at 01:08 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width