无需在每个usercontrol里边单个指定控件内gridview 隔行换色.只需要在主窗体内改成统一就好了
做到这点要明白.gridcontrol 是usercontrol 的子控件 , gridview是gridcontrol的子控件
通过for循环或者foreach 的方式查找各自的子控件,最终找到当前打开的gridview 窗体的对象.操作它. 修改属性.目的达到.上代码
//添加行变色 void ShowColor() { foreach (Control control in this.control.Controls) { if (control is GridControl) { GridControl grid = (GridControl)control; foreach (GridView item in grid.Views ) { if(item is GridView) { item.OptionsView.EnableAppearanceEvenRow = true; item.OptionsView.EnableAppearanceOddRow = true; item.Appearance.OddRow.BackColor = Color.AliceBlue; item.Appearance.OddRow.Options.UseBackColor = true; item.Appearance.EvenRow.BackColor = Color.AntiqueWhite; item.Appearance.OddRow.Options.UseBackColor = true; } } } } }
附上选色链接 https://www.cnblogs.com/xpvincent/archive/2012/12/17/2821665.html