G
gmahesh917
Hi All,
Please suggest me how we can do the formatting (e.g. BackColor
Changed) for perticular Item in combobox.?
I have done DrawMode = OwnerDrawFixed
and written following code in DrawItem Event :
private void comboBox1_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
Font fntTab;
Brush bshBack;
Brush bshFore;
if (e.Index == 0)
{
fntTab = new Font(e.Font, FontStyle.Bold);
Color customColor = Color.FromArgb(211, 211, 211);
bshBack = new SolidBrush(customColor);
bshFore = new SolidBrush(Color.Black);
}
else
{
fntTab = e.Font;
Color customColor = Color.FromArgb(255,255,255);
bshBack = new SolidBrush(customColor);
bshFore = new SolidBrush(Color.Black);
}
string tabName = this.comboBox1.Items[e.index].ToString();
StringFormat sftTab = new StringFormat();
e.Graphics.FillRectangle(bshBack, e.Bounds);
Rectangle recTab = e.Bounds;
recTab = new Rectangle(recTab.X, recTab.Y + 2, recTab.Width + 8,
recTab.Height - 2);
e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);
}
Everything works fine...
but
at line
string tabName = this.comboBox1.Items[e.index].ToString();
I get unhandled exception.
In this event e.Index is always -1
Please suggest solution...
Thanks in advance
Please suggest me how we can do the formatting (e.g. BackColor
Changed) for perticular Item in combobox.?
I have done DrawMode = OwnerDrawFixed
and written following code in DrawItem Event :
private void comboBox1_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
Font fntTab;
Brush bshBack;
Brush bshFore;
if (e.Index == 0)
{
fntTab = new Font(e.Font, FontStyle.Bold);
Color customColor = Color.FromArgb(211, 211, 211);
bshBack = new SolidBrush(customColor);
bshFore = new SolidBrush(Color.Black);
}
else
{
fntTab = e.Font;
Color customColor = Color.FromArgb(255,255,255);
bshBack = new SolidBrush(customColor);
bshFore = new SolidBrush(Color.Black);
}
string tabName = this.comboBox1.Items[e.index].ToString();
StringFormat sftTab = new StringFormat();
e.Graphics.FillRectangle(bshBack, e.Bounds);
Rectangle recTab = e.Bounds;
recTab = new Rectangle(recTab.X, recTab.Y + 2, recTab.Width + 8,
recTab.Height - 2);
e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);
}
Everything works fine...
but
at line
string tabName = this.comboBox1.Items[e.index].ToString();
I get unhandled exception.
In this event e.Index is always -1
Please suggest solution...
Thanks in advance