Thursday, May 17, 2012

CellMouseLeave/CellMouseMove เปลี่ยนสี backcolor ใน datagridview

private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1)
            {
                dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
                dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor  = Color.Black ;
            }
        }
        private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex != -1)
            {
                dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGray;
                dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Blue ;
            }
        }

No comments:

Post a Comment