Formular una preguntaFormular una pregunta
 

RespondidaHow can i show pictures in listbox?

  • viernes, 06 de noviembre de 2009 22:44mausmust Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    I have a listbox and there will be names in it.I want to display gender type icons in each line near peoples names. How can i do that in vb.net 2008 ?

Respuestas

  • sábado, 07 de noviembre de 2009 7:36jwavila Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    As Doug said, best to use a ListView

    Create an imagelist with your gender type images

    When adding items to the listview, use the index of the imagelist to add the appropriate image

    note: the images are added to the first column (must be added as the listview Item, not a SubItem). But you can switch the order of the columns using ListView.Columns.DisplayIndex to move the image column over if you want it like Name  Gender
    • Marcado como respuestamausmust sábado, 07 de noviembre de 2009 12:38
    •  
  • sábado, 07 de noviembre de 2009 12:38mausmust Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    Ok i solved it :D Commands i used:

                Dim item1 As New ListViewItem("", 0)
                item1.SubItems.Add("man1")
                ListView1.Items.Add(item1)

    and there is no ListView.Columns.DisplayIndex command so i just changed it in listview1's properties.

    Thanx everybody...
    • Marcado como respuestamausmust sábado, 07 de noviembre de 2009 12:38
    •  

Todas las respuestas

  • viernes, 06 de noviembre de 2009 23:37Malange Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
  • sábado, 07 de noviembre de 2009 5:00Doug__ Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    I'm not aware of any simple way to do what you ask with the ListBox.  It might be possible to do by drawing each of the items in the ListBox yourself (OwnerDraw).  The ListView control is already designed to display icons with each item.  You should look into using it instead of the ListBox.

    :)


    Doug

    SEARCH ... then ask
  • sábado, 07 de noviembre de 2009 7:36jwavila Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    As Doug said, best to use a ListView

    Create an imagelist with your gender type images

    When adding items to the listview, use the index of the imagelist to add the appropriate image

    note: the images are added to the first column (must be added as the listview Item, not a SubItem). But you can switch the order of the columns using ListView.Columns.DisplayIndex to move the image column over if you want it like Name  Gender
    • Marcado como respuestamausmust sábado, 07 de noviembre de 2009 12:38
    •  
  • sábado, 07 de noviembre de 2009 10:21mausmust Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Thanks for your answers.One thing i could't do is there is no ListView.Columns.DisplayIndex command? How can i change image column with name column?
  • sábado, 07 de noviembre de 2009 11:38Paramu Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    Dim ImageListSmall As New ImageList()

    ImageListSmall.Images.Add(Bitmap.FromFile("C:\MausMust\Item_desc.gif"))
    ImageListSmall.Images.Add(Bitmap.FromFile(
    "C:\MausMust\spec.gif"
    ))
    ImageListSmall.Images.Add(Bitmap.FromFile(
    "C:\MausMust\Item_spci.gif"))

    ListView1.Columns.Add("ITEM_DESCRIPTION", k1 + k2, HorizontalAlignment.Left)
    ListView1.Columns.Add(
    "ITEM_CODE"
    , k2, HorizontalAlignment.Left)
    ListView1.Columns.Add(
    "ITEM_SPECIFICATION"
    , k1, HorizontalAlignment.Left)
    ListView1.SmallImageList = ImageListSmall
    ListView1.Columns(0).ImageIndex = 0
    ListView1.Columns(1).ImageIndex = 1
    ListView1.Columns(2).ImageIndex = 2
    ListView1.Font =
    New System.Drawing.Font("Times New Roman", 8, FontStyle.Regular, GraphicsUnit.Point, Byte.MinValue)

     


    U.PARANTHAMAN
  • sábado, 07 de noviembre de 2009 11:54mausmust Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Thats cool but not solves my problem.In your description, there are icons in headers but what i want to do is change icon column with names column.Like that;

    People       |       Gender type icon

    Man1         | male icon

    Woman1    | female icon
    .                 .
    .                 .
    .                 .
                     

    Because when i insert items and icons to my listview, preview is just like that ;


    People         |      Gender type icon

    male icon     |      man1

    female icon  |      woman1
    .                          .
    .                          .
    .                          .


  • sábado, 07 de noviembre de 2009 12:38mausmust Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    Ok i solved it :D Commands i used:

                Dim item1 As New ListViewItem("", 0)
                item1.SubItems.Add("man1")
                ListView1.Items.Add(item1)

    and there is no ListView.Columns.DisplayIndex command so i just changed it in listview1's properties.

    Thanx everybody...
    • Marcado como respuestamausmust sábado, 07 de noviembre de 2009 12:38
    •  
  • sábado, 07 de noviembre de 2009 15:53jwavila Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Tiene código
    Hi mausmust

    this thread has been marked as answered, but in case you look at it again...

    because the icon will add to the "first" column, I set up my columns with the Gender column (to show the icon) first, but then tell it to Display that column second (index of 1)


    Dim imgList As New ImageList
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ListView1.View = View.Details
            ListView1.Width = 500
    
           
            ListView1.Columns.Add("Gender", 75, HorizontalAlignment.Left)
            ListView1.Columns.Add("Name", 100, HorizontalAlignment.Left)
            ListView1.Columns.Add("Notes", 350, HorizontalAlignment.Left)
            ListView1.AllowColumnReorder = True
    
            ListView1.Columns(0).DisplayIndex = 1
    
            imgList.Images.Add("Male", Image.FromFile("C:\Users\Joe\Pictures\Male-Symbol.jpg"))
            imgList.Images.Add("Female", Image.FromFile("C:\Users\Joe\Pictures\Female-Symbol.jpg"))
            ListView1.SmallImageList = imgList
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim index As Integer
            Select Case True
                Case RadioButton1.Checked
                    index = 0
                Case RadioButton2.Checked
                    index = 1
            End Select
    
            Dim lvi As New ListViewItem
            lvi.ImageIndex = index
            lvi.SubItems.Add(TextBox1.Text)
            ListView1.Items.Add(lvi)
    
        End Sub
    

  • domingo, 08 de noviembre de 2009 2:27--Steve-- Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    You take Doug's advice and use the ListView and then don't give him credit for an answer.  That's a real slap to his face!  Give him credit (mark as an answer) for pointing you to the correct control to use!