在DataGrid里面排序时,会激发什么事件?
能不能在激发排序的事件时得到按那个字段来排序和按升还是降排序?
多谢

解决方案 »

  1.   

    在web中,当启用排序时,网格将在每列的标题上呈现 LinkButton 控件。单击该按钮时,将引发网格的 SortCommand 事件。
    void MyDataGrid_Sort(Object sender, DataGridSortCommandEventArgs e) {
            SortField = (string)e.SortExpression;
            //BindGrid();
        }
      

  2.   

    winform中没有找到排序时,会激发的事件。
    我不知道楼主要做什么,不知道下面的代码对你是否有用:
    在鼠标按到排序headerColumn时屏蔽排序功能;
    private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
    // Use the DataGrid control's HitTest method with the x and y properties.
    myHitTest = dataGrid1.HitTest(e.X,e.Y);
    if(myHitTest.Type.ToString().Trim() == "ColumnHeader")    this.dataGrid1.AllowSorting = false;
    //you can add other code if you want
    }其实你要使不具备排序功能或是是他有排序功能你指定allowsorting即可;