Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:58:36+00:00 2026-06-05T01:58:36+00:00

I made a owner drawn combo box. This is how it is shown on

  • 0

I made a owner drawn combo box. This is how it is shown on the form. On the attachment, it is the combo box next to the OK button. please see the attachment. Instead of “Solid line- text” as the first selected, I need the solid line image to be displayed as first selection.

Image

Here’s my code:

 public partial class comboBoxLineStyle : ComboBox
{
    public comboBoxLineStyle()
    {
        InitializeComponent();
        this.DrawMode = DrawMode.OwnerDrawFixed;

    }
    protected override void OnDrawItem(DrawItemEventArgs e)
    {
        base.OnDrawItem(e);

        if (e.Index < 0) { return; }
        e.DrawBackground();
        ComboBoxItem item = (ComboBoxItem)this.Items[e.Index];
       e.Graphics.DrawImage(item.Picture,new Point(e.Bounds.X, e.Bounds.Y));

    }
    public new Image SelectedItem
    {
        get
        {
            return (Image)base.SelectedItem;
        }
        set
        {
            base.SelectedItem = value;
        }
    }
    public new Image SelectedValue
    {
        get
        {
            return (Image)base.SelectedValue;
        }
        set
        {
            base.SelectedValue = value;
        }
    }

}

public class ComboBoxItem
{
    public string text;
    public Image Picture;
    public Color foreColor;
    public override string ToString()
    {
        return text;
    }

    public ComboBoxItem() { }
    public ComboBoxItem(string pText, Image pValue)
    {
        text = pText;
        Picture = pValue;
    }
    public ComboBoxItem(string pText, Image pValue, Color pColor)
    {
        text = pText; Picture = pValue; foreColor = pColor;
    }


}

On the windows form:

        private void DlgGraphOptions_Load(object sender, EventArgs e)
    {
        ComboBoxItem item1Solid = new ComboBoxItem("Solid Line",Properties.Resources.Solidline);
        ComboBoxItem item1dash = new ComboBoxItem("Dashed Line", Properties.Resources.dashedline);
        ComboBoxItem item1dashed = new ComboBoxItem("Dashed Line", Properties.Resources.dashdash);


        comboBoxLineStyle1.Items.Add(item1Solid);
        comboBoxLineStyle1.Items.Add(item1dash);
        comboBoxLineStyle1.Items.Add(item1dashed);
        comboBoxLineStyle1.SelectedIndex = 0;

    }

I have comboBoxLineStyle1.SelectedIndex = 0, meaning it should set “itemsolid1-solidline- image. ” as the selected value.

But instead it shows “solid line-text”

Please suggest
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:58:37+00:00Added an answer on June 5, 2026 at 1:58 am

    Set the ComboBoxStyle to DropDownList. This disables the ability to enter text manually in the ComboBox. I guess that the picture will be displayed instead of the text then.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Made this nice little loop for hiding and showing div's, works as a charm
I forked a project on github, since then the original owner made changes to
I have two tables made in access. One table (Owner) contains: ownerID , name
I have an owner drawn header of a ListView control. If the header is
This is the day of weird behavior. We have a Win32 project made with
Made a custom obj called Item with some string fields and one float. .h
I made a function which displays date on the webpage,, and i uploaded the
I made the ultimate laugh generator using these rules. Can you implement it in
I made small program to divide large pictures and take part of them. When
I made the mistake of modifying my original source after importing it into subversion.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.