Dec 19th, 2003, 05:46 PM
#1
Thread Starter
Member
ListBox Formating :/ Left to Right
i do not think this is possible but if some one could comfirm that its not possible that in a listbox: you can not have a item like this:
Lord Of The Rings"no text here " £11.00
(cancel the " )
you need to make them two seperate lists boxes right or is there a way to align them
:/
cheers
Last edited by Ezpz; Dec 19th, 2003 at 06:02 PM .
Dec 19th, 2003, 06:02 PM
#2
Fanatic Member
Why don't you use the listview control. Then everything could be in its own colum.
Dec 19th, 2003, 06:12 PM
#3
Thread Starter
Member
at the moment i have two list box one called lstname and one called lstprice :/ well i want to use one and have the name on the left of the list box and next to the name on the far right have the price,
how would listcontrol get around that!? i have never used it before so an example or a website would be great cheers
Dec 19th, 2003, 07:06 PM
#4
Junior Member
Check this...
Check this...
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cool As Object
cool = ("Lord of the Rings") + (" ") + ("$11.00")
ListBox1.Items.Add(cool)
End Sub
Dec 19th, 2003, 07:09 PM
#5
Dec 20th, 2003, 04:06 AM
#6
Thread Starter
Member
yes mate that all the prices in line with each other, will i still be able to add them all up ye :/
Dec 20th, 2003, 07:29 AM
#7
Sleep mode
OK , this one way :
VB Code:
Private Sub AddItems()
Dim strArry() As String = {"Lord of the Rings", _
"Bad Boys 2003", _
"Terminator 3"}
Dim Prices() As String = {"£11.00", _
"£13.00", _
"£51.00"}
For i As Integer = 0 To strArry.Length - 1
Dim TmpStr As String = strArry(i).Insert(strArry(i).Length, " " + Prices(i))
ListBox1.Items.Add(TmpStr)
Next
End Sub
You can develop this method to do more efficiently on alignment and let it accept string arrays , do your formatting stuff based on the length of the input string .
Dec 20th, 2003, 08:04 AM
#8
Thread Starter
Member
Right heres my code,
VB Code:
Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click
If lbl2.Text = "3.25" Then
Dim strArry() As String = {lbl1.Text}
Dim Prices() As String = {D}
For i As Integer = 0 To strArry.Length - 1
Dim TmpStr As String = strArry(i).Insert(strArry(i).Length, " " + Prices(i))
lstboxname.Items.Add(TmpStr)
Next
ElseIf lbl2.Text = "2.55" Then
Dim strArry() As String = {lbl1.Text}
Dim Prices() As String = {V}
For i As Integer = 0 To strArry.Length - 1
Dim TmpStr As String = strArry(i).Insert(strArry(i).Length, " " + Prices(i))
lstboxname.Items.Add(TmpStr)
Next
ElseIf lbl2.Text = "1.55" Then
Dim strArry() As String = {lbl1.Text}
Dim Prices() As String = {P}
For i As Integer = 0 To strArry.Length - 1
Dim TmpStr As String = strArry(i).Insert(strArry(i).Length, " " + Prices(i))
lstboxname.Items.Add(TmpStr)
Next
End If
End Sub
The outcome of this code is :/ shown in the pic below
Attached Images
Dec 20th, 2003, 10:38 AM
#9
Sleep mode
In this case , you have to either use listview or use owner-drawn listboxitems . Edneeis has great example here http://www.edneeis.com/downloads/multicombo.zip . It's Combobox though it's exactly the same behaviour and methods.
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