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. Image for the cookie policy date

Sort column on a databoundgrid

What event gets fired when a user clicks on a column header to update the sort column and order? Also, the SortCol property allows the user to set a column for the sort order - is there a similar property that allows me to retrieve the current sort index? Thanks.

4 Replies

AD Administrator Syncfusion Team June 19, 2003 01:58 PM

The CellClick event fires before the sort is done. Youwould check teh row index to make sure the click is on a header cell. The sort direction is stored in the header's cells style.Tag property. Here are code snippets that show how you can get at it.
private void button1_Click(object sender, System.EventArgs e)
{
	for(int i = 1; i <= this.gridDataBoundGrid1.Model.ColCount; ++i)
		if(this.gridDataBoundGrid1[0,i].Tag is ListSortDirection)
		{
			MessageBox.Show((i.ToString() + " " + this.gridDataBoundGrid1[0,i].Tag.ToString());
		}
	}
}


RS Russell Simmons June 19, 2003 03:22 PM

What event fires after the sort is done? Unfortunately, it seems that when the CellClick event fires, the Tag property is not yet set. > The CellClick event fires before the sort is done. Youwould check teh row index to make sure the click is on a header cell. > > The sort direction is stored in the header's cells style.Tag property. Here are code snippets that show how you can get at it. >
> private void button1_Click(object sender, System.EventArgs e)
> {
> 	for(int i = 1; i <= this.gridDataBoundGrid1.Model.ColCount; ++i)
> 		if(this.gridDataBoundGrid1[0,i].Tag is ListSortDirection)
> 		{
> 			MessageBox.Show((i.ToString() + " " + this.gridDataBoundGrid1[0,i].Tag.ToString());
> 		}
> 	}
> }
> 


AD Administrator Syncfusion Team June 19, 2003 03:41 PM

I am afraid there is no good event yo catch this action. To catch it, you can derive the GridDataBoundGrid and override the SortColumn virtual method.
Public Class DataBoundSortGrid
    Inherits GridDataBoundGrid


    Public Overrides Sub SortColumn(ByVal colIndex As Integer)

        MyBase.SortColumn(colIndex)
	Console.WriteLine("After Sort")

    End Sub

End Class


RS Russell Simmons June 19, 2003 03:59 PM

Thank you. I figured out another way to do what I wanted to do. The info you sent was very helpful, though. > I am afraid there is no good event yo catch this action. To catch it, you can derive the GridDataBoundGrid and override the SortColumn virtual method. > >
> Public Class DataBoundSortGrid
>     Inherits GridDataBoundGrid
> 
> 
>     Public Overrides Sub SortColumn(ByVal colIndex As Integer)
> 
>         MyBase.SortColumn(colIndex)
> 	Console.WriteLine("After Sort")
> 
>     End Sub
> 
> End Class
> 
>

Loader.
Live Chat Icon For mobile
Up arrow icon