TheSwamp

Code Red => .NET => Topic started by: samideqlqpart on August 31, 2016, 04:41:21 PM

Title: Make a ComboBox display images or icons with text in vb.net
Post by: samideqlqpart 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
Title: Re: Make a ComboBox display images or icons with text in vb.net
Post by: BillZndl 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
Title: Re: Make a ComboBox display images or icons with text in vb.net
Post by: MexicanCustard on September 01, 2016, 07:14:11 AM
WPF. Just saying.
Title: Re: Make a ComboBox display images or icons with text in vb.net
Post by: MickD on September 01, 2016, 07:15:20 AM
google is your friend :)

http://www.codeproject.com/Articles/106467/How-to-Display-Images-in-ComboBox-in-Minutes
Title: Re: Make a ComboBox display images or icons with text in vb.net
Post by: Keith Brown 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 (https://www.syncfusion.com/products/communitylicense)

Title: Re: Make a ComboBox display images or icons with text in vb.net
Post by: MickD 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.
Title: Re: Make a ComboBox display images or icons with text in vb.net
Post by: samideqlqpart on September 02, 2016, 04:12:30 PM
thank you
i found this
very helpful
http://www.devasp.net/net/articles/display/365.html
Title: Re: Make a ComboBox display images or icons with text in vb.net
Post by: BillZndl on September 06, 2016, 03:32:29 PM
I couldn't get imagelist to work correctly either except on small 16x16 icons.
Title: Re: Make a ComboBox display images or icons with text in vb.net
Post by: MexicanCustard 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>