• DataGrid Sort


    我所使用过的DataGrid 排序方法。不同的代码适用不同的条件,一定要审慎用之啊。
    1、
    //  #region /***列排序***/
    //  public void SortColumn(DataGrid  dataGrid ,int columnIndex)
    //  {
    //   try
    //   {
    //    System.ComponentModel.PropertyDescriptor pd =
    //     dataGrid.TableStyles[0].GridColumnStyles[columnIndex].PropertyDescriptor;

    //  //if the above line of code didn't work try to get a propertydescriptor
    //  // via MappingName
    ////  if(pd == null)
    //// {
    ////  System.ComponentModel.PropertyDescriptorCollection pdc =
    ////   System.ComponentModel.TypeDescriptor.GetProperties(sourceType);
    ////  pd =
    ////  pdc.Find( this.TableStyles[0].GridColumnStyles[columnIndex].MappingName,
    ////  false);
    //// }
    //    //now invoke ColumnHeaderClicked method using system.reflection tools
    //    System.Reflection.MethodInfo mi =
    //     typeof(System.Windows.Forms.DataGrid).GetMethod("ColumnHeaderClicked",
    //     System.Reflection.BindingFlags.Instance |
    //     System.Reflection.BindingFlags.NonPublic);
    //    mi.Invoke(dataGrid, new object[] {pd});
    //   }
    //   catch (Exception err)
    //   {
    //    MessageBox.Show(this,err.Message.ToString(),"列排序",MessageBoxButtons.OK,MessageBoxIcon.Information); 
    //   }
    //  }
    //
    //  #endregion

    2、
    //  #region /***列排序***/
    //  public void SortDataGrid(object sender, System.Windows.Forms.MouseEventArgs e)
    //  {
    //   DataGrid.HitTestInfo hitTest;
    //   DataTable dataTable;
    //   DataView dataView;
    //   string columnName;
    //   DataGrid dataGrid;
    //
    //   // Use only left mouse button clicks.
    //   if (e.Button == MouseButtons.Left)
    //   {
    //    dataGrid = (DataGrid)sender;
    //    hitTest = dataGrid.HitTest(e.X, e.Y);
    //    if (hitTest.Type == DataGrid.HitTestType.ColumnHeader)
    //    {
    //     DataSet ds=(DataSet)dataGrid.DataSource;
    //     dataTable =ds.Tables[0];
    //     dataView= dataTable.DefaultView;
    //  
    //     if(dataGrid.TableStyles.Count != 0)
    //      columnName = dataGrid.TableStyles[0].GridColumnStyles[hitTest.Column].MappingName;
    //     else
    //      columnName = dataTable.Columns[hitTest.Column].ColumnName;
    //
    //     if (dataView.Sort == columnName)
    //      dataView.Sort = columnName + " DESC";
    //     else
    //      dataView.Sort = columnName;
    //    }
    //   }
    //  }
    //
    //  #endregion
    //
    //  private void dgDataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    //  {
    //   if(dgDataGrid.VisibleRowCount == 0) return;
    //   SortDataGrid(sender, e);
    //   dgDataGrid.Select(dgDataGrid.CurrentRowIndex);
    //  }
    //

  • 相关阅读:
    poj2594 Treasure Exploration 二分匹配之最小路径覆盖+传递闭包
    Qsort和Sort排序函数用法
    poj1696 Space Ant 卷包裹法 向量叉积比较
    poj1113 Wall 凸包问题 官方数据
    poj2187 Beauty Contest 凸包求点集的直径
    printf 里面的 %lf 要改成 %f G++,G++的浮点型需要%f输出,%lf就是WA!!!
    让IE6支持Fixed
    更改input type="file" 的样式
    Repeater心得
    Windows服务删除
  • 原文地址:https://www.cnblogs.com/flashicp/p/771549.html
Copyright © 2020-2023  润新知