社区
C#
帖子详情
DataGrid中如何改变某一列的颜色
dlxu
2006-07-31 09:57:03
感觉应该使用DataGridTextBoxColumn来设置,但是设置了DataGridTextBoxColumn的TextBox.ForeColor并没有反应,估计是别的属性,究竟如何,请大家指教,谢谢
...全文
371
11
打赏
收藏
DataGrid中如何改变某一列的颜色
感觉应该使用DataGridTextBoxColumn来设置,但是设置了DataGridTextBoxColumn的TextBox.ForeColor并没有反应,估计是别的属性,究竟如何,请大家指教,谢谢
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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>
C#实现
改变
DataGrid
某一行和单元格
颜色
的方法
主要介绍了C#实现
改变
DataGrid
某一行和单元格
颜色
的方法,主要涉及
DataGrid
控件的添加与使用、数据源的绑定、单元格与行的获取等操作。需要的朋友可以参考下
WPF
DataGrid
行的背景色根据行
中
某一字段的值来显示
WPF的
DataGrid
展示数据源数据时,需要根据某行
中
某一字段值,来显示背景
颜色
。这里简单做了一个int类型的值,为0的时候为橙色,为1的时候为草绿色....也可以在数据源
中
添加Color列,并直接存放Color的16进制值,并...
FLEX里
DataGrid
单元格渲染
某一行某
一列
的单元格背景或字体
颜色
变化,某一行某
一列
的单元格背景或字体
颜色
变化
asp.net专家疑难解答200问源码
114.如何把
DataGrid
中
某
一列
的统计值显示在页脚
中
115.如何在
DataGrid
中
让不同条件的行显示不同的背景
颜色
116.如何在
DataGrid
中
实现分页功能 117.如何实现鼠标移到
DataGrid
控件的某一行时
改变
该行的背景 118....
asp.net专家疑难解答200问
如何把
DataGrid
中
某
一列
的统计值显示在页脚
中
115.如何在
DataGrid
中
让不同条件的行显示不同的背景
颜色
116.如何在
DataGrid
中
实现分页功能 117.如何实现鼠标移到
DataGrid
控件的某一行时
改变
该行的背景 ...
C#
110,535
社区成员
642,575
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章