请尝试以下代码:
C#:- private void Form1_Load(object sender, EventArgs e)
- {
- this.gcMultiRow.CellFormatting += new EventHandler<CellFormattingEventArgs>(gcMultiRow_CellFormatting);
- this.gcMultiRow.RowEnter += new EventHandler<CellEventArgs>(gcMultiRow_RowEnterLeave);
- this.gcMultiRow.RowLeave += new EventHandler<CellEventArgs>(gcMultiRow_RowEnterLeave);
- }
- void gcMultiRow_RowEnterLeave(object sender, CellEventArgs e)
- {
- this.gcMultiRow.InvalidateRow(e.RowIndex);
- }
- void gcMultiRow_CellFormatting(object sender, CellFormattingEventArgs e)
- {
- if (e.Scope == CellScope.Row &&
- e.RowIndex == this.gcMultiRow.CurrentCellPosition.RowIndex)
- {
- e.CellStyle.BackColor = SystemColors.Highlight;
- }
- }
复制代码
VB:- Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
- AddHandler Me.gcMultiRow.CellFormatting, AddressOf gcMultiRow_CellFormatting
- AddHandler Me.gcMultiRow.RowEnter, AddressOf gcMultiRow_RowEnterLeave
- AddHandler Me.gcMultiRow.RowLeave, AddressOf gcMultiRow_RowEnterLeave
- End Sub
- Private Sub gcMultiRow_RowEnterLeave(ByVal sender As Object, ByVal e As CellEventArgs)
- Me.gcMultiRow.InvalidateRow(e.RowIndex)
- End Sub
- Private Sub gcMultiRow_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)
- If e.Scope = CellScope.Row AndAlso e.RowIndex = Me.gcMultiRow.CurrentCellPosition.RowIndex Then
- e.CellStyle.BackColor = SystemColors.Highlight
- End If
- End Sub
复制代码 |