Feb 4th, 2011, 11:42 PM
#1
Thread Starter
New Member
Feb 5th, 2011, 05:49 AM
#2
Addicted Member
Re: Help!!!! Please !!
this should be simple enough
i assume listbox is called ListBox1 and textbox is called TextBox1 and also that ur textbox is multiline
vb Code:
For Each item In ListBox1.Items
TextBox1.Text = TextBox1.Text & item & Environment.NewLine
Next
Feb 5th, 2011, 07:09 AM
#3
Re: Help!!!! Please !!
I've asked the mods to move this thread to the VB.NET forum. Always post in the most specific forum appropriate to the topic. Also, please provide descriptive titles for your threads. If everyone who wanted help use "Help" as the title then every single thread would be entitled "Help" and there would be nothing to distinguish them so we'd have to open every single one to know which was relevant.
vb_ftw's code will get the job done but it's not the best option. If you need to update a control its preferable to do it only once, so if you have multiple data items, you should combine them into one first, then update the control. There are various ways you could go about this but, assuming that there's either no data already in the TextBox or you want to replace the existing text, I'd do it this way:
vb.net Code:
Dim lines(Me.ListBox1.Items.Count - 1) As String
Me.ListBox1.Items.CopyTo(lines, 0)
Me.TextBox1.Lines = lines
Feb 5th, 2011, 07:38 AM
#4
Re: Help!!!! Please !!
Welcome to VBForums
It isn't clear from your post which version of VB you are using for this... can you tell us which version the Help -> About screen shows? (likely to be something like: VB 6.0, or VB 6.3, or VB 2008, etc)
Feb 5th, 2011, 08:17 AM
#5
Re: Help!!!! Please !!
Originally Posted by
si_the_geek
It isn't clear from your post which version of VB you are using for this
I've not used VB6 but I don't think "lstbox1.items.add(txtbox1.text)" would be valid in anything other than VB.NET would it?
Feb 5th, 2011, 08:26 AM
#6
Re: Help!!!! Please !!
Works the same for VB6
Delete it. They just clutter threads anyway.
Feb 5th, 2011, 12:05 PM
#7
Thread Starter
New Member
Re: Help!!!! Please !!
Originally Posted by
vb_ftw
this should be simple enough
i assume listbox is called ListBox1 and textbox is called TextBox1 and also that ur textbox is multiline
vb Code:
For Each item In ListBox1.Items
TextBox1.Text = TextBox1.Text & item & Environment.NewLine
Next
hmm i tried this just now and this line:
txtalpha.Text = txtalpha.Text & item & Environment.NewLine
got highlighted and an error saying:
Operator '&' is not defined for string "" and type 'ObjectCollection'.
idk what most errors mean, i'm not the best in vb and im still just starting
Feb 5th, 2011, 12:07 PM
#8
Re: Help!!!! Please !!
If you could tell us what VB version you are using, that would be a start.
Delete it. They just clutter threads anyway.
Feb 5th, 2011, 12:14 PM
#9
Thread Starter
New Member
Re: Help!!!! Please !!
Me.ListBox1.Items.CopyTo(lines, 0)
Me.TextBox1.Lines = lines[/HIGHLIGHT][/QUOTE]
i also tried your code and changed listbox1 and textbox1 to my names of those items
Code:
Dim lines(Me.lstalpha2.Items.Count - 1) As String
Me.lstalpha2.Items.CopyTo(lines, 0)
Me.txtalpha.Lines = lines
and with that i got this highlighted:
Me.lstalpha2.Items.CopyTo(lines, 0)
with the error message:
"Attempted to access an element as a type incompatible with the array."
the code makes sense though, i just cant figure out whats wrong
Feb 5th, 2011, 12:15 PM
#10
Thread Starter
New Member
Re: Help!!!! Please !!
Originally Posted by
si_the_geek
Welcome to VBForums
It isn't clear from your post which version of VB you are using for this... can you tell us which version the Help -> About screen shows? (likely to be something like: VB 6.0, or VB 6.3, or VB 2008, etc)
im using VB 2008 express edition
thanks for the reminder btw i meant to put that in my thread but i just forgot :P i'll update it now
Feb 5th, 2011, 12:17 PM
#11
Thread Starter
New Member
Re: Help!!!! Please !!
Originally Posted by
TheBigB
If you could tell us what VB version you are using, that would be a start.
just updated the thread to include that thanks for reminding me
Feb 5th, 2011, 12:53 PM
#12
Re: Help!!!! Please !!
Thread moved to 'VB.Net' (VB2002 and later) forum
Feb 5th, 2011, 01:28 PM
#13
Thread Starter
New Member
Re: Help!!!! Please !!
thanks for moving the thread i'm kinda new to the forums so i didnt know exactly where to put it :P.
anyways, anyone know how i can do this? the other 2 comments regarding code didnt work
Feb 5th, 2011, 04:14 PM
#14
Re: Help!!!! Please !!
how do you load your listbox? manually or from a datasource?
here's 3 possibilities:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'databound
TextBox1.Lines = Array.ConvertAll(ListBox1.Items.Cast(Of DataRowView).ToArray, Function(d As DataRowView) d.Item(ListBox1.DisplayMember).ToString)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'integer
TextBox2.Lines = Array.ConvertAll(ListBox2.Items.Cast(Of Integer).ToArray, Function(i) i.ToString)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'string
TextBox3.Lines = ListBox3.Items.Cast(Of String).ToArray
End Sub
Coding Examples:
Features:
Online Games:
Compiled Games:
Feb 5th, 2011, 04:20 PM
#15
Thread Starter
New Member
Re: Help!!!! Please !!
Originally Posted by
.paul.
how do you load your listbox? manually or from a datasource?
[/HIGHLIGHT]
im using a textbox to input what i want into the listbox... then i hit a button to alphabetize the listbox and take the words (now alphabetized) and insert them into the textbox...
I tried to use your code:
Code:
'string
txtalpha.Lines = lstalpha2.Items.Cast(Of String).ToArray
because the "string" option seemed most fitting...
anyways once i copied it and inputted the names of my textbox and lstbox and ran the program i got this part highlighted:
txtalpha.Lines = lstalpha2.Items.Cast(Of String).ToArray
and the error read:
Unable to cast object of type 'ObjectCollection' to type 'System.String'.
your code seems to make sense to me, but i dont understand why it doesnt work...
Feb 5th, 2011, 04:24 PM
#16
Re: Help!!!! Please !!
which framework are you targetting?
Coding Examples:
Features:
Online Games:
Compiled Games:
Feb 5th, 2011, 04:40 PM
#17
Thread Starter
New Member
Re: Help!!!! Please !!
Originally Posted by
.paul.
which framework are you targetting?
what do you mean framework?....
Feb 5th, 2011, 04:42 PM
#18
Re: Help!!!! Please !!
You can find it in project properties.
It's either 2.0, 3.0, 3.5 or 4 client profile (or something like it).
Delete it. They just clutter threads anyway.
Feb 5th, 2011, 04:49 PM
#19
Thread Starter
New Member
Re: Help!!!! Please !!
Originally Posted by
TheBigB
You can find it in project properties.
It's either 2.0, 3.0, 3.5 or 4 client profile (or something like it).
i checked the properties, couldnt find it... i cant see why it would be important though?
Feb 5th, 2011, 05:35 PM
#20
Re: Help!!!! Please !!
what sort of size is your project? could you zip it + upload it + i'll find the problem for you?
Coding Examples:
Features:
Online Games:
Compiled Games:
Feb 5th, 2011, 06:40 PM
#21
Thread Starter
New Member
Re: Help!!!! Please !!
Originally Posted by
.paul.
what sort of size is your project? could you zip it + upload it + i'll find the problem for you?
it's super small, not even like a full page of code... but yea, i'll see if i can upload it.. can i upload it to the thread? or what exactly would be the easiest way for this?
Feb 5th, 2011, 06:59 PM
#22
Re: Help!!!! Please !!
below the message editor window, click Go Advanced. then click (see image) to upload.
Attached Images
Coding Examples:
Features:
Online Games:
Compiled Games:
Feb 5th, 2011, 07:18 PM
#23
Thread Starter
New Member
Re: Help!!!! Please !!
Originally Posted by
.paul.
below the message editor window, click Go Advanced. then click (see image) to upload.
heres the file , sorry this takes so much time dude :P thank you so much for this
Attached Files
Feb 5th, 2011, 07:22 PM
#24
Re: Help!!!! Please !!
which button should add the list items to the textbox?
Coding Examples:
Features:
Online Games:
Compiled Games:
Feb 5th, 2011, 07:25 PM
#25
Re: Help!!!! Please !!
this worked for me:
vb Code:
Public Class crmalpha
Private Sub cmdalpha_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdalpha.Click
lstalpha2.Items.Add(lstalpha.Items)
lstalpha2.Sorted = True
txtalpha.Lines = lstalpha.Items.Cast(Of String).ToArray
End Sub
Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click
lstalpha.Items.Add(txt1.Text)
txt1.Text = ""
txt1.Focus()
End Sub
Private Sub cmddelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddelete.Click
lstalpha.Items.Remove(txt1.Text)
txt1.Text = ""
txt1.Focus()
End Sub
Private Sub lstalpha_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstalpha.Click
txt1.Text = lstalpha.Text
End Sub
End Class
Coding Examples:
Features:
Online Games:
Compiled Games:
Feb 5th, 2011, 07:31 PM
#26
Re: Help!!!! Please !!
ok i found it. you want to display the sorted items from lstalpha2 in the textbox:
vb Code:
Private Sub cmdalpha_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdalpha.Click
lstalpha2.Items.AddRange(lstalpha.Items.Cast(Of String).ToArray)
lstalpha2.Sorted = True
txtalpha.Lines = lstalpha2.Items.Cast(Of String).ToArray
End Sub
Coding Examples:
Features:
Online Games:
Compiled Games:
Feb 5th, 2011, 07:41 PM
#27
Coding Examples:
Features:
Online Games:
Compiled Games:
Feb 5th, 2011, 07:50 PM
#28
Thread Starter
New Member
Re: Help!!!! Please !!
thanks so much dude, your code worked and at first it didnt... but then i figured it out... it was my fault xD my code was pretty dumb :P anyways... as promised:
<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3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<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3
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