DataGrid中如何改变某一列的颜色 感觉应该使用DataGridTextBoxColumn来设置,但是设置了DataGridTextBoxColumn的TextBox.ForeColor并没有反应,估计是别的属性,究竟如何,请大家指教,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 变成模板列<div style="???"><div> ref:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q745q private void datagrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e){ if(e.Item.ItemType != ListItemType.Header &&e.Item.ItemType != ListItemType.Footer){e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#ADD8E6'");e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='#EBF2F9'");}}???? 谢谢楼上的几位,我这里问的不是ASP.NET的,而是WinForm中如何设置,谢谢 WinForm中的比较复杂,要进行重画dataGrid的 我目前是这样,但还有问题象文本对齐等private void dataGrid1_Paint(object sender, System.Windows.Forms.PaintEventArgs e){ DataGrid dg=(DataGrid)sender; int rowCount=((DataTable)dg.DataSource).Rows.Count; Rectangle rect; StringFormat sf=new StringFormat(); sf.FormatFlags =StringFormatFlags.DirectionRightToLeft; Pen pen=new Pen(Color.Red,1); try { for (int i=10;i<rowCount;i++) { int v0 = (int)dg[i,1] % 10; int v1 = (int)dg[i,8] % 10; rect=dg.GetCellBounds(i,8); if (v0 > 5) { if (v0 + v1 == 15) { //e.Graphics.FillRectangle(new SolidBrush(Color.DarkKhaki),rect); e.Graphics.DrawRectangle(pen,rect); //e.Graphics.DrawString(dg[i,8].ToString(),Font,new SolidBrush(Color.Black),rect,sf); } } else { if (v0 != 0 && v0 + v1 == 10) { e.Graphics.DrawRectangle(pen,rect); //e.Graphics.FillRectangle(new SolidBrush(Color.DarkKhaki),rect); //e.Graphics.DrawString(dg[i,8].ToString(),Font,new SolidBrush(Color.Black),rect,sf); } } int k0 = (int)dg[i - 1,10] % 10; int k1 = (int)dg[i - 1,11] % 10; int k2 = (int)dg[i - 3,12] % 10; int k3 = (int)dg[i - 1,13] % 10; int k4 = System.Math.Abs((int)dg[i - 1,14]) % 10; string s = dg[i - 1,15].ToString(); if (v1 == k0) { rect=dg.GetCellBounds(i-1,10); e.Graphics.DrawRectangle(pen,rect); //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect); //e.Graphics.DrawString(dg[i-1,10].ToString(),Font,new SolidBrush(Color.Black),rect,sf); } if (v1 == k1) { rect=dg.GetCellBounds(i-1,11); e.Graphics.DrawRectangle(pen,rect); //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect); //e.Graphics.DrawString(dg[i-1,11].ToString(),Font,new SolidBrush(Color.Black),rect,sf); } if (v1 == k2) { rect=dg.GetCellBounds(i-3,12); e.Graphics.DrawRectangle(pen,rect); //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect); //e.Graphics.DrawString(dg[i-3,12].ToString(),Font,new SolidBrush(Color.Black),rect,sf); } if (v1 == k3) { //dataGridView1.Rows[e.RowIndex - 1].Cells[13].Style.BackColor = Color.DarkSeaGreen; rect=dg.GetCellBounds(i-1,13); e.Graphics.DrawRectangle(pen,rect); //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect); //e.Graphics.DrawString(dg[i-1,13].ToString(),Font,new SolidBrush(Color.Black),rect,sf); } if (v1 == k4) { rect=dg.GetCellBounds(i-1,14); e.Graphics.DrawRectangle(pen,rect); //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect); //e.Graphics.DrawString(dg[i-1,14].ToString(),Font,new SolidBrush(Color.Black),rect,sf); } if (s.Length >0 && s.IndexOf(v1.ToString())<0) { rect=dg.GetCellBounds(i-1,15); e.Graphics.DrawRectangle(pen,rect); //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect); //e.Graphics.DrawString(dg[i-1,15].ToString(),Font,new SolidBrush(Color.Black),rect,sf); } } } catch { //错误调试用 }} e.Items[0].Cells[0].BackColor=Color.FromName("#ffffff"); datagridview1.Columns[2].DefaultCellStyle.BackColor = Color.Red; 我在.Net 1.1下开发的,没有datagridview啊,哎,头大啊,而且我不是在Datagrid的事件中,所以也没有event 现在做开发,哪还有人用最基础的DataGrid控件?有多少现成的盗版DataGrid已经写好,操作简便,还要你自己写Pen来改变dataGrid的颜色么?你可以查下Farpoint Spread或者UltraGrid 将表中多层数据绑定到treeview 同时还要能够查询等等操作 输入IP地址的控件是什么? 索引超出数组界限 如何用c#解析这段json代码?? 文本文件 最简单的FTP问题,获取流时提示“远程服务器返回错误: (530) 未登录” 【求助】关于“C#接口”几点想不明白的问题,谢谢你的指教! Dategrid 使用 Template 更新数据的问题!! 提取文本问题 我的第一款共享软件,大家给点建议。 SQLDMO备份数据库到底该怎么用? 为什么Server.Execute会导致系统的form身份验证实效?
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q745q
{
if(e.Item.ItemType != ListItemType.Header &&e.Item.ItemType != ListItemType.Footer)
{
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#ADD8E6'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='#EBF2F9'");
}
}????
象文本对齐等private void dataGrid1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
DataGrid dg=(DataGrid)sender;
int rowCount=((DataTable)dg.DataSource).Rows.Count;
Rectangle rect; StringFormat sf=new StringFormat();
sf.FormatFlags =StringFormatFlags.DirectionRightToLeft; Pen pen=new Pen(Color.Red,1); try
{
for (int i=10;i<rowCount;i++)
{
int v0 = (int)dg[i,1] % 10;
int v1 = (int)dg[i,8] % 10; rect=dg.GetCellBounds(i,8);
if (v0 > 5)
{
if (v0 + v1 == 15)
{
//e.Graphics.FillRectangle(new SolidBrush(Color.DarkKhaki),rect);
e.Graphics.DrawRectangle(pen,rect);
//e.Graphics.DrawString(dg[i,8].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
}
}
else
{
if (v0 != 0 && v0 + v1 == 10)
{
e.Graphics.DrawRectangle(pen,rect);
//e.Graphics.FillRectangle(new SolidBrush(Color.DarkKhaki),rect);
//e.Graphics.DrawString(dg[i,8].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
}
}
int k0 = (int)dg[i - 1,10] % 10;
int k1 = (int)dg[i - 1,11] % 10;
int k2 = (int)dg[i - 3,12] % 10;
int k3 = (int)dg[i - 1,13] % 10;
int k4 = System.Math.Abs((int)dg[i - 1,14]) % 10;
string s = dg[i - 1,15].ToString(); if (v1 == k0)
{
rect=dg.GetCellBounds(i-1,10);
e.Graphics.DrawRectangle(pen,rect);
//e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
//e.Graphics.DrawString(dg[i-1,10].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
}
if (v1 == k1)
{
rect=dg.GetCellBounds(i-1,11);
e.Graphics.DrawRectangle(pen,rect);
//e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
//e.Graphics.DrawString(dg[i-1,11].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
}
if (v1 == k2)
{
rect=dg.GetCellBounds(i-3,12);
e.Graphics.DrawRectangle(pen,rect);
//e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
//e.Graphics.DrawString(dg[i-3,12].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
}
if (v1 == k3)
{
//dataGridView1.Rows[e.RowIndex - 1].Cells[13].Style.BackColor = Color.DarkSeaGreen;
rect=dg.GetCellBounds(i-1,13);
e.Graphics.DrawRectangle(pen,rect);
//e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
//e.Graphics.DrawString(dg[i-1,13].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
}
if (v1 == k4)
{
rect=dg.GetCellBounds(i-1,14);
e.Graphics.DrawRectangle(pen,rect);
//e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
//e.Graphics.DrawString(dg[i-1,14].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
} if (s.Length >0 && s.IndexOf(v1.ToString())<0)
{
rect=dg.GetCellBounds(i-1,15);
e.Graphics.DrawRectangle(pen,rect);
//e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
//e.Graphics.DrawString(dg[i-1,15].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
}
}
}
catch
{
//错误调试用
}
}
有多少现成的盗版DataGrid已经写好,操作简便,还要你自己写Pen来改变dataGrid的颜色么?你可以查下Farpoint Spread或者UltraGrid