DataGridView.Sorted event breaks the grid (in some cases)

Answered
0
0

Hi,

I’m trying to move the vertical scrollbar to 0 after the user sorts a column. Best way to do this (in my opinion) is to handle the Sorted event like so:

Private Sub DataGridView1_Sorted(sender As Object, e As EventArgs) Handles DataGridView1.Sorted
If DataGridView1.VerticalScroll IsNot Nothing Then
DataGridView1.VerticalScroll.Value = 0
End If
End Sub

The code above doesn’t work because the event is fired before the sorting is done, or atleast the grid isn’t done processing because the VerticalScroll will be nothing at that event.

The following code breaks the app after you close the dialog.

Private Sub DataGridView1_Sorted(sender As Object, e As EventArgs) Handles DataGridView1.Sorted

Messagebox.Show(“You broke it(?)”)

End Sub

 

I’ve attached a sample.

I’m using 2.2.5.26

Thanks in advance!

Vincent

 

Attachment
  • You must to post comments
Best Answer
0
0

Hi
Important remark that Wisej makes it too easy to forget it’s a web system.

The Sorted event is fired after the data is sorted and its runned in the server. Its differente about the data displayed on the browser with the sorting of the rows.

The messagebox in the sorted event is blocking the sorting.

There is scrollcellintoview method and there is the currentcell property and the setcurrentcell method, that can help better with your task.

I adjunt a sample where can check difference betweeen scrollcellintoview and setcurrentcell

Regards

 

  • You must to post comments
0
0

Thanks for the explanation! I only know Visual Basic which I learned as a kid as a hobby. WiseJ made it super easy to keep my workflow pretty much the same but I guess my lack of knowledge of how it works behind the scenes makes me make mistakes.

 

I see an event, I use it. I will try to look further before asking questions :).

Thanks for the example!

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.