首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

winform DataGridView依据光标位置设置所在行的背景颜色

2013-01-05 
winform DataGridView根据光标位置设置所在行的背景颜色如题。。。[解决办法]private void gv_CellMouseEnter

winform DataGridView根据光标位置设置所在行的背景颜色
如题。。。
[解决办法]


private void gv_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1)
            {
                object prevIndex = gv.Tag;

                if (prevIndex == null 
[解决办法]
 !prevIndex.Equals(e.RowIndex))
                {
                    gv.Tag = e.RowIndex;
                    gv.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
                    gv.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Blue;
                }
            }
        }
        private void gv_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1)
            {
                gv.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
                gv.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.FromArgb(0, 64, 64);
            }
        }


热点排行