在datagridview中,如何设置鼠标经过行时,改变样式?谢谢~~~
解决方案 »
- 请问控件的Validating、Validated与自己在代码中注册一个LostFocus、GotFocuss事件是等价的吗?
- ListView能否批量选中后修改呢?见下文
- 短信猫接口调用
- 什么情况下需要使用隐式转换与显式转换
- c# 开发的EXE为什么不能在XP系统下面
- 是中国人就进来看---上海反日大游行。老子没分散也要淹割 -- 苟日的劣等动物!!!
- treelist 数据绑定中,设置KeyFieldName和ParentFieldName的值
- 360真心的玩具
- 问一个Picshow控件能否在C#中使用,怎么使用,如果不能,有没有想类似的控件
- C# 问大家一个问题,主窗体里面嵌套了一个子窗体,子窗体里的DataGridVIew控件有数据不显示
- 关于发布安装程序的一点疑惑??
- 熟悉界面设计的人进来帮个忙
private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
DataGridViewCellStyle newCellStyle = new DataGridViewCellStyle();
newCellStyle.....; dataGridView1.Rows[e.RowIndex].DefaultCellStyle = newCellStyle;
}
DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 & e.RowIndex >= 0) {
DataGridView dgv = (DataGridView)sender;
dgv(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Empty;
dgv(e.ColumnIndex, e.RowIndex).Style.SelectionBackColor = Color.Empty;
}
}
呵呵,修改并补充一下就可以了: private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 & e.RowIndex >= 0)
{
DataGridView dgv = (DataGridView)sender;
dgv[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Empty ;
dgv[e.ColumnIndex, e.RowIndex].Style.SelectionBackColor = Color.Empty ;
}
} private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 & e.RowIndex >= 0)
{
DataGridView dgv = (DataGridView)sender;
dgv[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Yellow;
dgv[e.ColumnIndex, e.RowIndex].Style.SelectionBackColor = Color.Red;
}
}
{
if (e.ColumnIndex >= 0 & e.RowIndex >= 0)
{
this.dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Empty;
}
} private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 & e.RowIndex >= 0)
{
this.dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Red;
}
}
private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 & e.RowIndex >= 0)
{
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
dataGridView1[i, e.RowIndex].Style.BackColor = Color.Empty;
}
}
}
//鼠标划过效果
private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 & e.RowIndex >= 0)
{
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
dataGridView1[i, e.RowIndex].Style.BackColor = Color.FromArgb(255, 204, 102);
}
}
}