/// ------------------------------------------------------------------------------------ /// <summary> /// Occurs when the DataGridView compares two cell values to perform a sort operation. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.Forms.DataGridViewSortCompareEventArgs"/> /// instance containing the event data.</param> /// ------------------------------------------------------------------------------------ private void OnSortCompare(object sender, DataGridViewSortCompareEventArgs e) { if (e.CellValue1 is ITsString && e.CellValue2 is ITsString) { if (m_cache != null) { Debug.Assert(GetIcuLocale(e.RowIndex1) == GetIcuLocale(e.RowIndex2)); string icuLocale = GetIcuLocale(e.RowIndex1); if (icuLocale != null) { if (icuLocale != m_lastIcuLocale) { CollatingEngine.Close(); CollatingEngine.Open(icuLocale); m_lastIcuLocale = icuLocale; } e.SortResult = CollatingEngine.Compare(((ITsString)e.CellValue1).Text, ((ITsString)e.CellValue2).Text, LgCollatingOptions.fcoDefault); e.Handled = true; return; } } e.SortResult = ((ITsString)e.CellValue1).Text.CompareTo( ((ITsString)e.CellValue2).Text); e.Handled = true; return; } e.Handled = false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares two objects and returns a value indicating whether one is less than, equal /// to, or greater than the other. /// </summary> /// <param name="x">The first object to compare.</param> /// <param name="y">The second object to compare.</param> /// <returns> /// Value Condition /// Less than zero = x is less than y. /// Zero = x equals y. /// Greater than zero = x is greater than y. /// </returns> /// <exception cref="T:System.ArgumentException">Neither x nor y implements the /// <see cref="T:System.IComparable"/> interface.-or- x and y are of different types and /// neither one can handle comparisons with the other. </exception> /// ------------------------------------------------------------------------------------ public int Compare(object x, object y) { if ((!(x is ITsString || x is string) || !(y is ITsString || y is string)) && x != null && y != null) { throw new ArgumentException(); } string xString = (x is ITsString) ? ((ITsString)x).Text : x as string; string yString = (y is ITsString) ? ((ITsString)y).Text : y as string; if (xString == string.Empty) { xString = null; } if (yString == string.Empty) { yString = null; } if (xString == null && yString == null) { return(0); } if (xString == null) { return(-1); } if (yString == null) { return(1); } int ret; if (CollatingEngine != null) { ret = CollatingEngine.Compare(xString, yString, LgCollatingOptions.fcoDefault); } else { ret = xString.CompareTo(yString); } return(ret); }