社区
C#
帖子详情
如何改变DataGrid的任意一个cell的颜色
starkey
2003-08-05 10:27:33
别告诉我要什么DataGridStyle,因为我是DataGrid直接绑定一张DataTable,根本没有用到DataGridStyle。
多谢多谢,253,253
...全文
79
13
打赏
收藏
如何改变DataGrid的任意一个cell的颜色
别告诉我要什么DataGridStyle,因为我是DataGrid直接绑定一张DataTable,根本没有用到DataGridStyle。 多谢多谢,253,253
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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
WPF
DataGrid
选中行
颜色
不
改变
问题
找到一位仁兄写的资料,困扰我好几天的问题z
改变
DataGrid
某一行和单元格的
颜色
前段时间做WPF项目,需要
改变
DataGrid
某一行的
颜色
、高度,以及某个单元格的
颜色
、单元格字体的
颜色
,自然就必需取到
datagrid
的一行和一行的单元格,网上也是搜索了好久才找到,记录下来便于使用。 1、前台WPF界面添加
一个
DataGrid
控件,并添加两列(便于编写,达到目的即可) <
DataGrid
AutoGenerateColumns="False" ...
【WPF】通过修改
dataGrid
的
cell
的style,
改变
选中行失去焦点时的
颜色
<Style TargetType="{x:Type
DataGrid
Cell
}"> <Style.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter Property="B...
WPF
DataGrid
改变
单元格字体
颜色
或单元格背景
颜色
(一)
我是把博文当记事本的地方…… WPF
DataGrid
改变
单元格字体
颜色
或单元格背景
颜色
(一) 第一种方法,指定
DataGrid
里单元格的值是否符合用户自定义的条件,如果不,
改变
指定的
颜色
: 前台XAML代码: <Window x:Class="Wpf
DataGrid
Cell
Colors.MainWindow" xmlns="http://schemas.micr...
easyui
datagrid
表头样式和
改变
datagrid
中columns一行的背景
颜色
//easyui
datagrid
表头样式 <style> .
datagrid
-header-row td{background-color:#72A2DC;color:#fff;text-align:center} </style> //
改变
一行的背景
颜色
//单独
改变
一列的背景
颜色
{field:‘列名’,title:‘标题’,width:100, styler: function (value, row, index) { if(value==
C#
111,129
社区成员
642,541
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章