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);
我怎样才能赶上组合框在数据网格视图组合框列的事件? – Elmex
DataGridViewComboBoxEditingControl类的文档具有 一个示例,说明如何完全按照您的需要进行操作:http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxeditingcontrol.aspx它显示了如何连接到网格中承载的 组合框上的SelectedIndexChanged事件。 –