• 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);
    //  }
    //

  • 相关阅读:
    Codeforces 1065C Make It Equal
    Codeforces 1065B Vasya and Isolated Vertices
    Codeforces 1065A Vasya and Chocolate
    Luogu P2467 [SDOI2010]地精部落
    Codeforces 1042C Array Product
    Codeforces 1041C Coffee Break
    JMeter安装和环境变量搭建
    Jenkins
    Jenkins介绍
    Docker
  • 原文地址:https://www.cnblogs.com/flashicp/p/771549.html
Copyright © 2020-2023  润新知