We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to catch datagrid's sort event?(Click one ColumnHeader)

Thread ID:

Created:

Updated:

Platform:

Replies:

1341 Oct 20,2002 09:27 AM Jan 24,2004 02:39 AM Windows Forms 8
loading
Tags: FAQ
Jackfan
Asked On October 20, 2002 09:27 AM

How to catch datagrid's sort event?(Click one ColumnHeader)

Administrator [Syncfusion]
Replied On October 20, 2002 04:12 PM

You can catch the click on a columnheader and avoid sorting by deriving DataGrid and overriding OnMouseUp.
public class MyDataGrid: DataGrid
{
	protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
	{
		Point p1 = new Point(e.X, e.Y);
		DataGrid.HitTestInfo hti = this.HitTest(p1);
		if(hti.Type != HitTestType.ColumnHeader)
			base.OnMouseUp(e);
	}
}

Nicolas
Replied On November 7, 2002 05:42 AM

This works perfectly but it occurs before the sort event, and then doesn't enable to catch the selected value after the sort event. Is it an other way to proceed ? Nico

Thomas
Replied On November 7, 2002 02:34 PM

Are you trying to grab the sort events return value or are you trying to grab the value of a highlighted element in the grid?

Nicolas
Replied On November 8, 2002 12:57 AM

I'm trying to grab the value of a highlighted element in the grid. The problem is that the click event occurs before the sort event, and that the sort does not generate a currentcell_changed event. I'have look at some MS examples "vb.net 101 samples - VB.NET - Data Access - Build a Master-Detail Windows Form' and when i sort a datagrid the rest of the form is not anymore correctly binded. So i think that the only way to proceed is to set the datagrid property sort to false, and to catch the click event on the column header, and then to manually sort the grid.

Thomas
Replied On November 8, 2002 08:58 AM

Actually, there's an FAQ article on this site that deals with this issue. Try this link: http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q934q That should take you to the article. Hope that helps.

Thomas
Replied On November 8, 2002 08:58 AM

Actually, there's a FAQ article on this site that deals with this issue. Try this link: http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q934q That should take you to the article. Hope that helps.

jim
Replied On February 2, 2003 05:59 PM

If it's bound it's easy: take the View's ListChanged event.... You get a "reset" event in the ViewList changed event. This is the best way to catch sorting if you have a bound grid.... AddHandler dtMaster.DefaultView.ListChanged, AddressOf HandleMasterViewListChange Protected Overrides Sub HandleMasterViewListChange(ByVal sender As Object, ByVal args As System.ComponentModel.ListChangedEventArgs) 'This is a great event: You get a "RESET" when you sort, or even delete. 'Too bad it doesn't fire when you move between rows! If args.ListChangedType = System.ComponentModel.ListChangedType.Reset _ Or args.ListChangedType = System.ComponentModel.ListChangedType.ItemDeleted Then 'Need to refresh detail grid FilterDetailGrid(GetCurrentMasterRow) End If End Sub

SrimuruganG
Replied On January 24, 2004 02:39 AM

Insteed of these things Please paste the following datagrid Class and Follow the Steps, which is given below the code. Public Class FSDataGrid Inherits System.Windows.Forms.DataGrid Protected Overloads Overrides Sub OnMouseUp(ByVal e As MouseEventArgs) If (Me.HitTest(e.X, e.Y).Type <> DataGrid.HitTestType.ColumnHeader) Then MyBase.OnMouseUp(e) Else MyBase.OnMouseUp(e) MyBase.OnCurrentCellChanged(e) End If End Sub End Class Steps to Follow : 1. Paste the above code inside the Namespace. 2. Goto #Region " Windows Form Designer generated code " there you can find the Declaration of the datagrid. 3. Insteed of System.Windows.Forms.Datagrid give the Name of the Class (Namespace).FSDatagrid. Declare Like "Friend WithEvents DataGrid1 As Test.FSDataGrid" where - Test is Namespace. 4. Change it in the Sub InitializeComponent(). 5. I hope it will work fine.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;