winform中庸datagridview行变色问题 在datagridview当鼠标移到某行时,该行改变颜色,有高手帮忙写个吗。(winform中)加急 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你代码你参考下:双击GridView的OnRowDataBound事件;在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示:protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { int i; //执行循环,保证每条数据都可以更新 for (i = 0; i < GridView1.Rows.Count; i++) { //首先判断是否是数据行 if (e.Row.RowType == DataControlRowType.DataRow) { //当鼠标停留时更改背景色 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'"); //当鼠标移开时还原背景色 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c"); } } } 楼上的大哥,你这是Web的,这样的网上一大把.现在是winform.我也想弄.一直没找到合适. 4楼的大哥,你看清楚问题啊,winform的不是web的 if (e.Row.Selected == true){ DataGridViewCellStyle style=new DataGridViewCellStyle(); style.BackColor=Color.Red; dataGridView.RowsDefaultCellStyle = style;}鼠标移过的我没有找到这个事件.只有选中时的.我也想求鼠标移过的.呵呵 在MouseUp事件写,鼠标点过,也行,怎么写啊 具体的好像是 SelectedColor 和 SelectedForeColor private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red; } } private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White; } } private void gv_All_List_CellMouseEnter(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { this.gv_All_List.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red; } } private void gv_All_List_CellMouseLeave(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { for (int i = 1; i < this.gv_All_List.Rows.Count; ) { this.gv_All_List.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.WhiteSmoke; i += 2; } this.gv_All_List.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White; } } //鼠标经过 private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e) { if(e.RowIndex>=0) { if (e.RowIndex != -1 && e.ColumnIndex != -1) { this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red; } } } //鼠标离开 private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { if(e.RowIndex != -1 && e.ColumnIndex != -1 ) { this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = System.Drawing.Color.WhiteSmoke; } this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White; } //鼠标经过 private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e) { if(e.RowIndex>=0) { if (e.RowIndex != -1 && e.ColumnIndex != -1) { this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red; } } } //鼠标离开 private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { if(e.RowIndex != -1 && e.ColumnIndex != -1 ) { this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = System.Drawing.Color.WhiteSmoke; } this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White; } Winform 多线程问题 请教正则表达式,匹配bdhd://到.rmvb VB调用另存为对话框并保存为txt文件 请问ASP.NET读取数据库的WORD后,如何存放到某个路径下? 再次发帖求助,生成伪随机数 请教一个C#,Sytem.Timers.Timer的问题 大家来发表下意见呢 问个打包问题 如何读取这个数据库文件? 如何在屏幕上取词?就象金山词霸一样. 用过TeeChart的朋友们请进来帮帮我.... c#设置excel字体大小时速度很慢,需要等一两秒。
在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i;
//执行循环,保证每条数据都可以更新
for (i = 0; i < GridView1.Rows.Count; i++)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
}
不是web的
if (e.Row.Selected == true)
{
DataGridViewCellStyle style=new DataGridViewCellStyle();
style.BackColor=Color.Red;
dataGridView.RowsDefaultCellStyle = style;
}鼠标移过的我没有找到这个事件.只有选中时的.我也想求鼠标移过的.呵呵
private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
}
} private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
}
}
{
if (e.RowIndex >= 0)
{
this.gv_All_List.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
}
} private void gv_All_List_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
for (int i = 1; i < this.gv_All_List.Rows.Count; )
{
this.gv_All_List.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.WhiteSmoke; i += 2;
}
this.gv_All_List.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
}
}
private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
{
if(e.RowIndex>=0)
{
if (e.RowIndex != -1 && e.ColumnIndex != -1)
{
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
}
}
}
//鼠标离开
private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
if(e.RowIndex != -1 && e.ColumnIndex != -1 )
{
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = System.Drawing.Color.WhiteSmoke;
}
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White; }
private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
{
if(e.RowIndex>=0)
{
if (e.RowIndex != -1 && e.ColumnIndex != -1)
{
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
}
}
}
//鼠标离开
private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
if(e.RowIndex != -1 && e.ColumnIndex != -1 )
{
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = System.Drawing.Color.WhiteSmoke;
}
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White; }