如何更改活动单元格行和列的背景颜色

如何更改活动单元格行和列的背景颜色

本文介绍了如何更改活动单元格行和列的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi I'm new in vb and I want to change row and column backcolor for active cell but my code not work well
:





我的尝试:





What I have tried:

Dim col_index As Byte
Dim row_index As Byte
Private Sub dgv1_CellEnter_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv1.CellEnter
    Try
        If dgv1.CurrentCell.ColumnIndex > 0 Then
            TextBox1.Text = dgv1.CurrentRow.Cells.Item("stu_sery").Value
            index = dgv1.CurrentRow.Index
            ComboBox1.SelectedIndex = dgv1.CurrentCell.ColumnIndex - 1
            dgv1.Columns(dgv1.CurrentCell.ColumnIndex).DefaultCellStyle.BackColor = Color.Aqua
            dgv1.Rows(dgv1.CurrentCell.RowIndex).DefaultCellStyle.BackColor = Color.Aqua
            dgv1.Columns(col_index).DefaultCellStyle.BackColor= Color.White
            dgv1.Rows(row_index).DefaultCellStyle.BackColor = Color.White

            row_index = dgv1.CurrentCell.RowIndex
            col_index = dgv1.CurrentCell.ColumnIndex
        End If
    Catch ex As Exception

    End Try
End Sub

推荐答案


这篇关于如何更改活动单元格行和列的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 00:56