Author Topic: Problem with ComboBox DrawItem  (Read 1836 times)

0 Members and 1 Guest are viewing this topic.

latour_g

  • Newt
  • Posts: 184
Problem with ComboBox DrawItem
« on: February 29, 2016, 11:57:03 AM »
Hi,
I have a problem with my combobox list, I want to put a little image beside each item on my list  so I use the event DrawItem.
The problem is when the combobox drop down, the list is blank and I only see the description when my mouse is on the item.
I can't figure out what I'm doing wrong. 

Code - C#: [Select]
  1.         private void cboStandard_DrawItem(object sender, DrawItemEventArgs e)
  2.         {
  3.            cbo_DrawItem((ComboBox)sender, e, this.ilStandard);
  4.         }
  5.         //
  6.         //
  7.         private void cbo_DrawItem(ComboBox cbo, DrawItemEventArgs e, ImageList img)
  8.         {
  9.             if (e.Index < 0) return;
  10.             if (cbo.SelectedIndex < 0) return;
  11.  
  12.             string text = "-";
  13.  
  14.             if (cbo.SelectedIndex > -1)
  15.             {
  16.                 UTIL.CfgStd Blk = Blk = (UTIL.CfgStd)UT.aStandard[cbo.SelectedIndex];
  17.                 text = Blk.Des;
  18.             }
  19.  
  20.             e.DrawBackground();
  21.             using (SolidBrush br = new SolidBrush(e.ForeColor))
  22.             { e.Graphics.DrawString(text, e.Font, br, e.Bounds); }
  23.             if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
  24.                 e.DrawFocusRectangle();
  25.  
  26.             e.DrawBackground();
  27.             e.DrawFocusRectangle();
  28.  
  29.             string s = "";
  30.  
  31.             if (e.Index > -1 && img.Images.Count > e.Index)
  32.             {
  33.                 e.Graphics.DrawImage(img.Images[e.Index], new PointF(e.Bounds.X, e.Bounds.Y));
  34.                 s = "       " + ((UTIL.CfgStd)UT.aStandard[cbo.SelectedIndex]).Des;
  35.                 e.Graphics.DrawString(s, e.Font, Brushes.Black, new Point(e.Bounds.X, e.Bounds.Y));
  36.             }
  37.         }
  38.  
  39.