社区
C#
帖子详情
如何改变DataGrid的任意一个cell的颜色
starkey
2003-08-05 10:27:33
别告诉我要什么DataGridStyle,因为我是DataGrid直接绑定一张DataTable,根本没有用到DataGridStyle。
多谢多谢,253,253
...全文
48
13
打赏
收藏
如何改变DataGrid的任意一个cell的颜色
别告诉我要什么DataGridStyle,因为我是DataGrid直接绑定一张DataTable,根本没有用到DataGridStyle。 多谢多谢,253,253
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
13 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
Ani
2003-08-05
打赏
举报
回复
up
myhero811104
2003-08-05
打赏
举报
回复
WebForm中
DataGrid1.Items[i].Cells[j].BackColor = Color.Red;
i,j 是第几行、第几列
myhero811104
2003-08-05
打赏
举报
回复
WebForm中
DataGrid1.Items[i].Cells[j].BackColor = Color.Red;
i,j 是第几行、第几列
ddy2000
2003-08-05
打赏
举报
回复
up
starkey
2003-08-05
打赏
举报
回复
楼上的这样做法我看到过,好像要把DataGridColoredTextBoxColumn添加到DataGridStyle里面的。
我说过,我是DataGrid直接绑定DataTable,根本没用到什么DataGridSytle。
而且楼上的这种做法只能处理一列,好像两列就没办法了。
因为对于不同的列,paint是一样的,但我用来判断的数据格式就有可能不一样。
另外我的一张DataGrid绑定了不同的DataTable,用上面的方法恐怕会非常非常麻烦。
雪狼1234567
2003-08-05
打赏
举报
回复
根据值得的不同显示不同的颜色
public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
{
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush
foreBrush, bool alignToRight)
{
// the idea is to conditionally set the foreBrush and/or backbrush
// depending upon some crireria on the cell value
// Here, we color anything that begins with a letter higher than 'F'
try{
object o = this.GetColumnValueAtRow(source, rowNum);
if( o!= null)
{
char c = ((string)o)[0];
if( c > 'F')
{
// could be as simple as
// backBrush = new SolidBrush(Color.Pink);
// or something fancier...
backBrush = new LinearGradientBrush(bounds,
Color.FromArgb(255, 200, 200),
Color.FromArgb(128, 20, 20),
LinearGradientMode.BackwardDiagonal);
foreBrush = new SolidBrush(Color.White);
}
}
}
catch(Exception ex){ /* empty catch */ }
finally{
// make sure the base class gets called to do the drawing with
// the possibly changed brushes
base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
}
}
}
brightheroes
2003-08-05
打赏
举报
回复
www.C-sharpcorner.com
search datagrid
or
http://www.syncfusion.com/FAQ/WinForms/
starkey
2003-08-05
打赏
举报
回复
继续up,没有人知道吗
我C#用的时间不长,C#里还有句柄这个概念吗
liduke(天下有雪) 能不能说具体点
qimeizhi
2003-08-05
打赏
举报
回复
to heroux(FlyerAero):
System.Windows.Forms.DataGrid 没有items属性,System.web中倒是有,只是我们现在做的时窗体应用程序!
heroux
2003-08-05
打赏
举报
回复
用得着大家写的那么麻烦吗?
如下:
DataGrid1.Items[1].Cells[1].Attributes["style"]="COLOR: #ff00ff";
qimeizhi
2003-08-05
打赏
举报
回复
我也遇到类似的问题,关注中~!!!
http://expert.csdn.net/Expert/topic/2110/2110057.xml?temp=.1420404
liduke
2003-08-05
打赏
举报
回复
得到当前cell的句柄,就可以通过它的属性来对它的着色进行处理了
MarcuseXiao
2003-08-05
打赏
举报
回复
up
DataGrid
View控件.
DataGrid
View控件.
DataGrid
View的结构。操作数据。数据绑定。DataError事件
silverlight
datagrid
改变
颜色
WPF
DataGrid
多表头/列头,多行头,合并单元格,一列占据多行
先上效果图: 思路说明:这是两个
DataGrid
,没有嵌套,位置和高度保持一致,在加上ScrollViewer滚动条,这就像是在
一个
DataGrid
中。 缺点: 因为最外层有透明的Border,所以没有办法去点击任何
一个
单元格,也选中不了。 也可以将最层的Border去掉,但是这样一来,鼠标便不能在窗体的
任意
位置进行滚动。选中单元格的时候不会选择到两个
Datagrid
的...
使用 ASP+
DataGrid
控件来创建主视图/详细资料视图
Nikhil KothariMicrosoft Corporation 2000年8月简介 Microsoft® Visual Studio.NET 的下一发行版包括
DataGrid
Web 控件 (作为服务器控件的 Active Server Page+ (ASP+) 套件的一部分)。 该控件提供用以根据数据源的内容来表示 HTML 的功能。
DataGrid
控件可以用于若干个只读汇报
开源:VS.NET打印思想与2003/5
DataGrid
、
DataGrid
View及二维数据如ListView等终极打印实现(全部源码)
开源:VS.NET打印思想与2003/5
DataGrid
、
DataGrid
View及二维数据如ListView等终极打印实现(全部源码)关 键 字:VS.NET、打印、
DataGrid
、
DataGrid
View、ListView、DataTable、二维数据打印日 期:2005-12-16金质打印通:下载源码 文章摘要通过核心的打印二维网格的程序,无论你用的是VS.NET2
C#
111,097
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章