【发布时间】:2011-10-07 12:42:53
【问题描述】:
我有一个带有组合框列的 Winform datagridview。是否可以为组合框中的特定项目着色?如果是,我该怎么做(在 C# 中)?
【问题讨论】:
标签: c# .net winforms datagridview
我有一个带有组合框列的 Winform datagridview。是否可以为组合框中的特定项目着色?如果是,我该怎么做(在 C# 中)?
【问题讨论】:
标签: c# .net winforms datagridview
使用 ComboBox1_DrawItem
protected void ComboBox1_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
float size = 0;
System.Drawing.Font myFont;
FontFamily font= null;
//Color and font based on index//
Brush brush;
switch(e.Index)
{
case 0:
size = 10;
brush = Brushes.Red;
family = font.GenericSansSerif;
break;
case 1:
size = 20;
brush = Brushes.Green;
font = font.GenericMonospace;
break;
}
myFont = new Font(font, size, FontStyle.Bold);
string text = ((ComboBox)sender).Items[e.Index].ToString();
e.Graphics.DrawString(text, myFont, brush, e.Bounds.X, e.Bounds.Y);
【讨论】:
当单元格进入edit mode时,处理EditingControlShowing事件以执行编辑控件的自定义初始化。
看看this线程。
【讨论】: