DataGrid中如何改变某一列的颜色

dlxu 2006-07-31 09:57:03
感觉应该使用DataGridTextBoxColumn来设置,但是设置了DataGridTextBoxColumn的TextBox.ForeColor并没有反应,估计是别的属性,究竟如何,请大家指教,谢谢
...全文
371 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
鼻涕蛋蛋 2006-08-07
  • 打赏
  • 举报
回复
mark
dlxu 2006-08-01
  • 打赏
  • 举报
回复
谢谢楼上的几位,我这里问的不是ASP.NET的,而是WinForm中如何设置,谢谢
dlxu 2006-08-01
  • 打赏
  • 举报
回复
我在.Net 1.1下开发的,没有datagridview啊,哎,头大啊,而且我不是在Datagrid的事件中,所以也没有event
yespie 2006-08-01
  • 打赏
  • 举报
回复


datagridview1.Columns[2].DefaultCellStyle.BackColor = Color.Red;
kmxinqing 2006-08-01
  • 打赏
  • 举报
回复
e.Items[0].Cells[0].BackColor=Color.FromName("#ffffff");
xlfancy 2006-08-01
  • 打赏
  • 举报
回复
我目前是这样,但还有问题
象文本对齐。。。等

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
{
//错误调试用
}
}
Miceson chan 2006-08-01
  • 打赏
  • 举报
回复
WinForm中的比较复杂,要进行重画dataGrid的
lovebingye 2006-08-01
  • 打赏
  • 举报
回复
现在做开发,哪还有人用最基础的DataGrid控件?
有多少现成的盗版DataGrid已经写好,操作简便,还要你自己写Pen来改变dataGrid的颜色么?

你可以查下Farpoint Spread或者UltraGrid
qiuchuanxian 2006-07-31
  • 打赏
  • 举报
回复
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'");
}
}

????
Knight94 2006-07-31
  • 打赏
  • 举报
回复
ref:
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q745q
hawk_vip 2006-07-31
  • 打赏
  • 举报
回复
变成模板列<div style="???"><div>

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧