Link to home
Start Free TrialLog in
Avatar of T Hoecherl
T HoecherlFlag for United States of America

asked on

vb.net. Launching code after the column header has been clicked to sort

I want this code to be executed, every time a column header has been clicked to sort the column:

        Dim intRows As Integer

        intRows = dgvProdBatch.Rows.Count - 2
        dgvProdBatch.Rows(intRows).DefaultCellStyle.ForeColor = Color.White
        dgvProdBatch.Rows(intRows).Cells(7).Style.ForeColor = Color.Red
        dgvProdBatch.Rows(intRows).Cells(8).Style.ForeColor = Color.Red

This is what I tried, but this code doesn't ever execute:

    Private Sub dgvprodbatch_columnheadermouseclick(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs)
        Dim intRows As Integer

        intRows = dgvProdBatch.Rows.Count - 2
        dgvProdBatch.Rows(intRows).DefaultCellStyle.ForeColor = Color.White
        dgvProdBatch.Rows(intRows).Cells(7).Style.ForeColor = Color.Red
        dgvProdBatch.Rows(intRows).Cells(8).Style.ForeColor = Color.Red
    End Sub

How can I accomplish this task?
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

I enable sorting in the datagrid properties
 User generated image
Avatar of T Hoecherl

ASKER

I have already done that and the columns sort properly.  That's not the problem.  But each time any column is sorted, after the sort is finished, I want the font color of the last row to be reset.  Hence, the code:

        Dim intRows As Integer

         intRows = dgvProdBatch.Rows.Count - 2
         dgvProdBatch.Rows(intRows).DefaultCellStyle.ForeColor = Color.White
         dgvProdBatch.Rows(intRows).Cells(7).Style.ForeColor = Color.Red
         dgvProdBatch.Rows(intRows).Cells(8).Style.ForeColor = Color.Red

What I don't know how to do is recognize the sorting process as an event that I can use to launch this code.
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you David.  That did it.