What events can I trap when a datagrid is sorted by clicking the column header?

I have a datagrid that uses a datagridstyle that allows for sorting (by clicking column header).
I made my own textcolumnstyle and added a method that would allow me to resize the dimensions of the cell based on the contents it holds.

My method works fine and the grid is able to display the cells wholly whenever I initialize the grid's contents (updating the data source).

However, once I click on the column header for sorting purposes, the cells in the grid are redrawn to their default (or minimum) width and height, thus cutting the display of cells with rather long texts (it supports multiline display).

I tried calling the method for resizing in the Paint method of the textcolumnstyle.
This initially solves my problem but the user is now unable to resize the dimensions of the cell, which is not good.

So I thought maybe I could call my resizing method in one of the events that happens during sorting.
What I found on the internet were mostly for ASP .NET and seems to be not applicable in my case.

Does anybody have a suggestion for me?

Should I disallow sorting from clicking column header and instead make a combo box that would let the user choose which column to sort? But in this case, how do I sort the grid then? I have a datatable as the data source of the grid.
DrkLightAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

anvCommented:
the SortCommand event is also fired in this case..

with the click event of the datagrid.


0
DrkLightAuthor Commented:
How do I display the SortCommand event in the code editor?
It is not on "available" for the grid object I created(at least, it is not in the list of overrideable events).
Or are you suggesting I put something in the click event of my grid object?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

anvCommented:
0
DrkLightAuthor Commented:
Thank you for the link.

But liike I said in my original post, this seems to be applicable only to ASP.NET.

Also, the sort event is not available in the list of events for my grid object in the code editor.

Do I have to declare it myself?
0
RonaldBiemansCommented:
Hi DrkLight,

Have you tried creating your own datagrid and override the mousedown event

like

Public Class MyDataGrid
 Inherits DataGrid
 
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
 
Dim pt As New Point(e.X, e.Y)  
Dim hti As DataGrid.HitTestInfo = Me.HitTest(pt)

MyBase.OnMouseDown(e)
 
If hti.Type = HitTestType.ColumnHeader Then
 
' do your stuff here
 
End If
 
End Sub
End Class
 

 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.