-
May 21st, 2016, 01:20 PM
#1
Thread Starter
New Member
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
-
May 21st, 2016, 03:32 PM
#2
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
-
May 21st, 2016, 03:38 PM
#3
Hyperactive Member
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:
Sub Other5() Dim Cur As Integer = 5 Dim TB As TextBox = TextBox6 Dim TB1Lines As New List(Of String)(TextBox1.Lines) Dim TB2Lines As New List(Of String)(TextBox2.Lines) Dim TB4Lines As New List(Of String)(TextBox4.Lines) Dim TB5Lines As New List(Of String)(TextBox5.Lines) Dim TB6Lines As New List(Of String)(TextBox6.Lines) Dim Lines As New List(Of String) For a = 1 To 5 If Cur = 1 Then Lines = TB1Lines TB = TextBox1 ElseIf Cur = 2 Then Lines = TB2Lines TB = TextBox2 ElseIf Cur = 3 Then Lines = TB4Lines TB = TextBox4 ElseIf Cur = 4 Then Lines = TB5Lines TB = TextBox5 ElseIf Cur = 5 Then Lines = TB6Lines TB = TextBox6 End If If Cur = 0 = False Then For x As Integer = Lines.Count - 1 To 0 Step -1 If Lines(x).ToString.Length > 0 Then If CInt(Lines(x).ToString) > 2 = True Then Lines.Remove(Lines(x).ToString) End If End If Next Cur = Cur - 1 End If TB.Lines = Lines.ToArray Next End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim Lines As New List(Of String)(TextBox3.Lines) For x As Integer = Lines.Count - 1 To 0 Step -1 If Lines(x).ToString.Length > 0 Then If CInt(Lines(x).ToString) > 2 = True Then 'removes all the lines that were removed from textbox3 Call Other5() 'removes the items from textbox3 Lines.Remove(Lines(x).ToString) End If End If Next TextBox3.Lines = Lines.ToArray 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.
-
May 22nd, 2016, 11:10 AM
#4
Thread Starter
New Member
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?
-
May 22nd, 2016, 04:20 PM
#5
Thread Starter
New Member
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:
Dim list1 As List(Of String) = TextBox1.Lines.ToList Dim list2 As List(Of String) = TextBox2.Lines.ToList Dim list3 As List(Of String) = TextBox3.Lines.ToList Dim list4 As List(Of String) = TextBox4.Lines.ToList Dim list5 As List(Of String) = TextBox5.Lines.ToList Dim list6 As List(Of String) = TextBox6.Lines.ToList Dim t As Int32 Dim lin As String t = 1 lin = TextBox4.Lines(t).ToString() Do Until t = TextBox4.Lines.Count If lin > 2 Then list1.RemoveAt(t) TextBox1.Lines = list1.ToArray list2.RemoveAt(t) TextBox2.Lines = list2.ToArray list3.RemoveAt(t) TextBox3.Lines = list3.ToArray list5.RemoveAt(t) TextBox5.Lines = list5.ToArray list6.RemoveAt(t) TextBox6.Lines = list6.ToArray list4.RemoveAt(t) TextBox4.Lines = list4.ToArray t += 1 End If Loop
Last edited by FunkyDexter; May 23rd, 2016 at 04:30 AM.
Reason: Added code tags
-
May 23rd, 2016, 04:32 AM
#6
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
-
May 23rd, 2016, 09:02 AM
#7
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
-
May 23rd, 2016, 12:39 PM
#8
Hyperactive Member
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:
Dim TB1Lines As New List(Of String)(TextBox1.Lines) Dim TB2Lines As New List(Of String)(TextBox2.Lines) Dim TB3Lines As New List(Of String)(TextBox3.Lines) Dim TB5Lines As New List(Of String)(TextBox5.Lines) Dim TB6Lines As New List(Of String)(TextBox6.Lines) Dim Lines As New List(Of String)(TextBox4.Lines) For x As Integer = Lines.Count - 1 To 0 Step -1 If Lines(x).ToString.Length > 0 Then If CInt(Lines(x).ToString) > 2 = True Then TB1Lines.Remove(TB1Lines(x).ToString) TB2Lines.Remove(TB2Lines(x).ToString) TB3Lines.Remove(TB3Lines(x).ToString) TB5Lines.Remove(TB5Lines(x).ToString) TB6Lines.Remove(TB6Lines(x).ToString) Lines.Remove(Lines(x).ToString) TextBox1.Lines = TB1Lines.ToArray TextBox2.Lines = TB2Lines.ToArray TextBox3.Lines = TB3Lines.ToArray TextBox5.Lines = TB5Lines.ToArray TextBox6.Lines = TB6Lines.ToArray TextBox4.Lines = Lines.ToArray End If End If 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|