• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

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.
0
DrkLight
Asked:
DrkLight
  • 3
  • 2
1 Solution
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now