Author Topic: Make a ComboBox display images or icons with text in vb.net  (Read 6612 times)

0 Members and 1 Guest are viewing this topic.

samideqlqpart

  • Newt
  • Posts: 40
Make a ComboBox display images or icons with text in vb.net
« on: August 31, 2016, 04:41:21 PM »
 hello everybody

my problem is how to make a ComboBox that displays either a series of color samples or a list of images
or how to make a ComboBox that displays a series of images with associated text.

i've made one but
icons in my combobox are not like i want
here is my code and result

Private Sub ComboBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem

        If (e.Index <> -1) Then

            e.Graphics.DrawImage(ImageList1.Images(e.Index), e.Bounds.Left, e.Bounds.Top)

            e.Graphics.DrawString(Me.ComboBox1.Items(e.Index).ToString(), e.Font, System.Drawing.Brushes.Black, e.Bounds.Left + ImageList1.Images(e.Index).Width, e.Bounds.Top)
           
        End If

    End Sub

thank you

BillZndl

  • Guest
Re: Make a ComboBox display images or icons with text in vb.net
« Reply #1 on: September 01, 2016, 06:30:37 AM »
I would think an imageList control should handle this.

Or, just use listview:
Code - C#: [Select]
  1. listView1.View = View.Details; // Enables Details view so you can see columns
  2. listView1.Items.Add(new ListViewItem { ImageIndex = 0, Text = "Image 1" });
  3.  

Source:
http://stackoverflow.com/questions/17151776/c-sharp-listview-adding-item-with-image-and-text-and-align-the-text-to-left
« Last Edit: September 01, 2016, 06:50:04 AM by BillZndl »

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Make a ComboBox display images or icons with text in vb.net
« Reply #2 on: September 01, 2016, 07:14:11 AM »
WPF. Just saying.
Revit 2019, AMEP 2019 64bit Win 10

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Make a ComboBox display images or icons with text in vb.net
« Reply #4 on: September 01, 2016, 07:38:57 AM »
Syncfusion has a free set of controls for individuals and small businesses.   I do not use the controls personally but they do have a combobox that looks like it might work for what you want.


https://www.syncfusion.com/products/communitylicense

Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Make a ComboBox display images or icons with text in vb.net
« Reply #5 on: September 01, 2016, 06:42:29 PM »
So it seems as though you now have some options, as MexicanCustard suggested, WPF is your best solution even if learning how is a bit harder than WinForms, you get a lot more control of the appearance of your forms.

Whatever you choose, give it a go and if you get stuck I'm sure we can give you more specific help once you have some code to review.
cheers.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

samideqlqpart

  • Newt
  • Posts: 40
Re: Make a ComboBox display images or icons with text in vb.net
« Reply #6 on: September 02, 2016, 04:12:30 PM »
thank you
i found this
very helpful
http://www.devasp.net/net/articles/display/365.html

BillZndl

  • Guest
Re: Make a ComboBox display images or icons with text in vb.net
« Reply #7 on: September 06, 2016, 03:32:29 PM »
I couldn't get imagelist to work correctly either except on small 16x16 icons.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Make a ComboBox display images or icons with text in vb.net
« Reply #8 on: September 06, 2016, 04:27:56 PM »
Just to show how simple this would be using WPF.

Code: [Select]
<Window>
    <Window.Resources>
        <DataTemplate DataType="{x:Type MyClass}">
            < StackPanel Orientation="Horizontal">
                <Image Source="{Binding Image}" Width="20" Height="20"/>
                <TextBlock Text="{Binding Text}"/>
            </StackPanel>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <ListBox ItemsSource="{Binding MyList}"/>
    </Grid>
</Window>
Revit 2019, AMEP 2019 64bit Win 10