Results 1 to 9 of 9

Thread: ListBox Formating :/ Left to Right

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    55

    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.

  2. #2
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770
    Why don't you use the listview control. Then everything could be in its own colum.

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    55
    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

  4. #4
    Junior Member
    Join Date
    Oct 2003
    Posts
    17

    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

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    this ?
    Attached Images Attached Images  

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    55
    yes mate that all the prices in line with each other, will i still be able to add them all up ye :/

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    OK , this one way :
    VB Code:
    1. Private Sub AddItems()
    2.         Dim strArry() As String = {"Lord of the Rings", _
    3.                                     "Bad Boys 2003", _
    4.                                     "Terminator 3"}
    5.  
    6.         Dim Prices() As String = {"£11.00", _
    7.                                   "£13.00", _
    8.                                   "£51.00"}
    9.  
    10.         For i As Integer = 0 To strArry.Length - 1
    11.             Dim TmpStr As String = strArry(i).Insert(strArry(i).Length, "     " + Prices(i))
    12.             ListBox1.Items.Add(TmpStr)
    13.         Next
    14.  
    15.     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 .

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    55
    Right heres my code,

    VB Code:
    1. Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click
    2.         If lbl2.Text = "3.25" Then
    3.             Dim strArry() As String = {lbl1.Text}
    4.             Dim Prices() As String = {D}
    5.             For i As Integer = 0 To strArry.Length - 1
    6.                 Dim TmpStr As String = strArry(i).Insert(strArry(i).Length, "      " + Prices(i))
    7.                 lstboxname.Items.Add(TmpStr)
    8.             Next
    9.         ElseIf lbl2.Text = "2.55" Then
    10.             Dim strArry() As String = {lbl1.Text}
    11.             Dim Prices() As String = {V}
    12.             For i As Integer = 0 To strArry.Length - 1
    13.                 Dim TmpStr As String = strArry(i).Insert(strArry(i).Length, "      " + Prices(i))
    14.                 lstboxname.Items.Add(TmpStr)
    15.             Next
    16.         ElseIf lbl2.Text = "1.55" Then
    17.             Dim strArry() As String = {lbl1.Text}
    18.             Dim Prices() As String = {P}
    19.             For i As Integer = 0 To strArry.Length - 1
    20.                 Dim TmpStr As String = strArry(i).Insert(strArry(i).Length, "      " + Prices(i))
    21.                 lstboxname.Items.Add(TmpStr)
    22.             Next
    23.         End If
    24.     End Sub

    The outcome of this code is :/ shown in the pic below
    Attached Images Attached Images  

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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
  •  



Click Here to Expand Forum to Full Width