private void GridViewColumnHeader_Click(object sender, RoutedEventArgs e) { GridViewColumnHeader column = (sender as GridViewColumnHeader); string sortBy = column.Tag.ToString(); if (listViewSortCol != null) { AdornerLayer.GetAdornerLayer(listViewSortCol).Remove(listViewSortAdorner); carList.Items.SortDescriptions.Clear(); } ListSortDirection newDir = ListSortDirection.Ascending; if (listViewSortCol == column && listViewSortAdorner.Direction == newDir) { newDir = ListSortDirection.Descending; } listViewSortCol = column; listViewSortAdorner = new SortAdorner(listViewSortCol, newDir); AdornerLayer.GetAdornerLayer(listViewSortCol).Add(listViewSortAdorner); var tempItems = items.ToArray(); if (sortBy == "carId") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareCarsByIdAscending); } else { Array.Sort(tempItems, CompareCarsByIdDescending); } } else if (sortBy == "registration") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareCarsByRegistrationAscending); } else { Array.Sort(tempItems, CompareCarsByRegistrationDescending); } } carList.ItemsSource = tempItems; CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(carList.ItemsSource); view.SortDescriptions.Add(new SortDescription("carId", ListSortDirection.Descending)); view.Filter += UserFilter; }
/// <summary> /// Update the column header based on the sort column and order. /// </summary> private void UpdateHeaderTemplate() { Style headerStyle; // Restore the previous header. if (previousSortColumn != null && previousSortColumn.SortStyle != null) { headerStyle = this.TryFindResource(previousSortColumn.SortStyle) as Style; if (headerStyle != null) { previousSortColumn.HeaderContainerStyle = headerStyle; } } // Update the current header. if (sortColumn.SortStyle != null) { // The name of the resource to use for the header. string resourceName = sortColumn.SortStyle + sortDirection.ToString(); headerStyle = this.TryFindResource(resourceName) as Style; if (headerStyle != null) { sortColumn.HeaderContainerStyle = headerStyle; } } }
/// <summary> /// Apply Sorting /// </summary> /// <param name="property"></param> /// <param name="direction"></param> public void Sort(PropertyDescriptor property, ListSortDirection direction) { if (_databaseModeEnabled) { // Build the Linq Expression tree for sorting string sortFieldName = property.Name; string sortMethod = "OrderBy"; if (direction.ToString() == "Descending") { sortMethod = "OrderbyDescending"; } var queryableData = _session.Query <SongData>(); var type = typeof(SongData); var prop = type.GetProperty(sortFieldName); var parameter = Expression.Parameter(type, "p"); var propertyAccess = Expression.MakeMemberAccess(parameter, prop); var orderByExpression = Expression.Lambda(propertyAccess, parameter); var queryExpr = Expression.Call(typeof(Queryable), sortMethod, new[] { type, property.PropertyType }, queryableData.Expression, Expression.Quote(orderByExpression)); var result = queryableData.Provider.CreateQuery <SongData>(queryExpr); _dbIdList.Clear(); foreach (SongData dataObject in result) { _dbIdList.Add(dataObject.Id); } } }
private static MethodInfo GetThen(Type typeSrc, Type typeResult, ListSortDirection direction) { string name; switch (direction) { case ListSortDirection.Ascending: name = nameof(Queryable.ThenBy); break; case ListSortDirection.Descending: name = nameof(Queryable.ThenByDescending); break; default: throw new NotSupportedException(direction.ToString()); } return(_methodDictionary2.GetOrAdd((name, typeSrc, typeResult, 2), MethodFactory)); }
/// <summary> /// Evaluate the sorting of the given <paramref name="sequence"/> of strings, ensuring that it's /// sorted in the <paramref name="direction"/> specified. /// </summary> /// <param name="sequence">The enumerable of strings to evaluate.</param> /// <param name="direction">The <see cref="ListSortDirection"/> expected.</param> public static void AssertSequenceSorting(IEnumerable<string> sequence, ListSortDirection direction, string message) { int expectedCompare = direction == ListSortDirection.Ascending ? -1 : +1; string previousItem = null; foreach (string item in sequence) { if (previousItem != null) { int actualCompare = previousItem.CompareTo(item); if (!(actualCompare == expectedCompare || actualCompare == 0)) { Assert.Fail(string.Format("Sequence is not sorted in {0} order: {1}. {2}", direction.ToString(), string.Join(", ", sequence.ToArray()), message)); } } previousItem = item; } }
private void Sort(string sortBy, ListSortDirection direction) { ICollectionView dataView = CollectionViewSource.GetDefaultView(List.ItemsSource); string orderColumn = sortBy; var items = List.ItemsSource as IEnumerable <Order>; switch (orderColumn) { case "Fecha": //ordenamos la lista decendientemente if (direction.ToString() == "Descending") { List.ItemsSource = items.OrderByDescending(a => a.StartDate); } //ascendiente else { List.ItemsSource = items.OrderBy(a => a.StartDate); } break; case "Factoria": //ordenamos la lista decendientemente if (direction.ToString() == "Descending") { List.ItemsSource = items.OrderByDescending(a => a.Factory.Name); } //ascendiente else { List.ItemsSource = items.OrderBy(a => a.Factory.Name); } break; case "Pedido": //ordenamos la lista decendientemente if (direction.ToString() == "Descending") { List.ItemsSource = items.OrderByDescending(a => a.Reference); } //ascendiente else { List.ItemsSource = items.OrderBy(a => a.Reference); } break; case "Vehiculo": //ordenamos la lista decendientemente if (direction.ToString() == "Descending") { List.ItemsSource = items.OrderByDescending(a => a.VehicleType); } //ascendiente else { List.ItemsSource = items.OrderBy(a => a.VehicleType); } break; case "Cantidad": //ordenamos la lista decendientemente if (direction.ToString() == "Descending") { List.ItemsSource = items.OrderByDescending(a => a.ReceivedAmount); } //ascendiente else { List.ItemsSource = items.OrderBy(a => a.ReceivedAmount); } break; case "Cliente": //ordenamos la lista decendientemente if (direction.ToString() == "Descending") { List.ItemsSource = items.OrderByDescending(a => a.Client.Name); } //ascendiente else { List.ItemsSource = items.OrderBy(a => a.Client.Name); } break; default: //ordenamos la lista decendientemente if (direction.ToString() == "Descending") { List.ItemsSource = items.OrderByDescending(a => a.Client.Name); } //ascendiente else { List.ItemsSource = items.OrderBy(a => a.Client.Name); } break; } }
/// <summary> /// Evaluate the sorting of the given <paramref name="sequence"/> of strings, ensuring that it's /// sorted in the <paramref name="direction"/> specified. /// </summary> /// <param name="sequence">The enumerable of strings to evaluate.</param> /// <param name="direction">The <see cref="ListSortDirection"/> expected.</param> public static void AssertSequenceSorting(IEnumerable <string> sequence, ListSortDirection direction, string message) { int expectedCompare = direction == ListSortDirection.Ascending ? -1 : +1; string previousItem = null; foreach (string item in sequence) { if (previousItem != null) { int actualCompare = previousItem.CompareTo(item); if (!(actualCompare == expectedCompare || actualCompare == 0)) { Assert.Fail(string.Format("Sequence is not sorted in {0} order: {1}. {2}", direction.ToString(), string.Join(", ", sequence.ToArray()), message)); } } previousItem = item; } }
protected override void Invoke(object parameter) { switch (((parameter as System.Windows.RoutedEventArgs).Source as System.Windows.Controls.Button).Name) { case "button1": ListSortDirection dir = (this.Target.DataContext as ViewModel).GetSortDirection(); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.SortedColumns.Clear(); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.SortedColumns.Add("B", dir); (this.Target.DataContext as ViewModel).SetTitleLine("Sorted On B using default " + dir.ToString()); break; case "button2": //listSortedOnBcomparer (this.Target.DataContext as ViewModel).SetTitleLine("Sorted On B using custom Comparer"); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.SortedColumns.Clear(); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.SortedColumns.Add("B"); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.SortedColumns["B"].Comparer = new BComparer(); break; case "button3": //groupByC (this.Target.DataContext as ViewModel).SetTitleLine("GroupBy C"); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.GroupedColumns.Clear(); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.GroupedColumns.Add("C", (this.Target.DataContext as ViewModel).GetSortDirection()); break; case "button4": //groupByC (this.Target.DataContext as ViewModel).SetTitleLine("GroupBy CD"); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.GroupedColumns.Clear(); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.GroupedColumns.Add("C", (this.Target.DataContext as ViewModel).GetSortDirection()); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.GroupedColumns.Add("D", (this.Target.DataContext as ViewModel).GetSortDirection()); // ShowGrouping(); break; case "button5": //Filter string s = (this.Target.DataContext as ViewModel).FilterString; FilterCompareOperator op; string name; string compareValue; if ((this.Target.DataContext as ViewModel).ParseFilter(s, out name, out op, out compareValue)) { (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.RecordFilters.Clear(); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.RecordFilters.Add(name, op, compareValue); (this.Target.DataContext as ViewModel).SetTitleLine("Filter by: " + name + " " + op.ToString() + " " + compareValue.ToString()); } break; case "button6": string mappingName = (this.Target.DataContext as ViewModel).MappingName; string name1 = mappingName; (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.Summaries.Add(name1, mappingName, (SummaryType)((this.Target.DataContext as ViewModel).SelectedIndexVal)); break; case "button7": (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.Summaries.Clear(); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.GroupedColumns.Clear(); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.SortedColumns.Clear(); (this.Target.DataContext as ViewModel).TheTable.TableDescriptor.RecordFilters.Clear(); break; case "button8": (this.Target.DataContext as ViewModel).TextBox1 = string.Empty; break; case "button9": //rawList (this.Target.DataContext as ViewModel).SetTitleLine("Raw List"); //A.commented code shows particular property //PropertyDescriptorCollection pdc = theTable.GetItemProperties(); //PropertyDescriptor pd = pdc["B"]; int i = 0; foreach (Record r in (this.Target.DataContext as ViewModel).TheTable.UnsortedRecords) { //this.textBox1.Text += string.Format("[{0}] \t {1}", i, r.GetData()) + Environment.NewLine; (this.Target.DataContext as ViewModel).TextBox1 += string.Format(" \t {1}", i, r.GetData()) + Environment.NewLine; //B.commented code shows particular property //this.textBox1.Text += pd.GetValue(r.Data).ToString() + Environment.NewLine; ++i; } break; case "button10": (this.Target.DataContext as ViewModel).NItems = (int)(this.Target.DataContext as ViewModel).ItemCount; (this.Target.DataContext as ViewModel).Engine.SetSourceList((this.Target.DataContext as ViewModel).CreateADataSource()); (this.Target.DataContext as ViewModel).TheTable = (this.Target.DataContext as ViewModel).Engine.Table; break; case "button11": (this.Target.DataContext as ViewModel).Show("DisplayElements", (this.Target.DataContext as ViewModel).TheTable.DisplayElements); break; case "button12": (this.Target.DataContext as ViewModel).Show("Elements", (this.Target.DataContext as ViewModel).TheTable.Elements); break; case "button13": (this.Target.DataContext as ViewModel).Show("FilteredRecords", (this.Target.DataContext as ViewModel).TheTable.FilteredRecords); break; case "button14": (this.Target.DataContext as ViewModel).Show("SortedRecords", (this.Target.DataContext as ViewModel).TheTable.Records); break; case "button15": (this.Target.DataContext as ViewModel).TheTable.ExpandAllGroups(); (this.Target.DataContext as ViewModel).SetTitleLine("ExpandAllGroups"); break; case "button16": (this.Target.DataContext as ViewModel).CollapseGroup((this.Target.DataContext as ViewModel).TheTable.TopLevelGroup); (this.Target.DataContext as ViewModel).SetTitleLine("CollapseAllGroups"); break; } }
/// <summary> /// Serves as a hash function for a particular type. <see cref="M:System.Object.GetHashCode"></see> is suitable for use in hashing algorithms and data structures like a hash table. /// </summary> /// <returns> /// A hash code for the current <see cref="T:System.Object"></see>. /// </returns> public override int GetHashCode() { return((name + dir.ToString()).GetHashCode()); }
private void GridViewColumnHeader_Click(object sender, RoutedEventArgs e) { GridViewColumnHeader column = (sender as GridViewColumnHeader); string sortBy = column.Tag.ToString(); if (listViewSortCol != null) { AdornerLayer.GetAdornerLayer(listViewSortCol).Remove(listViewSortAdorner); ListViewLends.Items.SortDescriptions.Clear(); } ListSortDirection newDir = ListSortDirection.Ascending; if (listViewSortCol == column && listViewSortAdorner.Direction == newDir) { newDir = ListSortDirection.Descending; } listViewSortCol = column; listViewSortAdorner = new SortAdorner(listViewSortCol, newDir); AdornerLayer.GetAdornerLayer(listViewSortCol).Add(listViewSortAdorner); var tempItems = items.ToArray(); if (sortBy == "LendId") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareLendByIdAscending); } else { Array.Sort(tempItems, CompareLendByIdDescending); } } else if (sortBy == "Person") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareLendByPersonAscending); } else { Array.Sort(tempItems, CompareLendByPersonDescending); } } else if (sortBy == "LendStart") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareLendByDateStartAscending); } else { Array.Sort(tempItems, CompareLendByDateStartDescending); } } else if (sortBy == "PlannedLendEnd") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareLendByDatePlannedEndAscending); } else { Array.Sort(tempItems, CompareLendByDatePlannedEndDescending); } } else if (sortBy == "LendEnd") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareLendByDateEndAscending); } else { Array.Sort(tempItems, CompareLendByDateEndDescending); } } else if (sortBy == "DateReservation") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareLendByDateReservationAscending); } else { Array.Sort(tempItems, CompareLendByDateReservationDescending); } } else if (sortBy == "Car") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareCarAscending); } else { Array.Sort(tempItems, CompareCarDescending); } } ListViewLends.ItemsSource = tempItems; CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(ListViewLends.ItemsSource); view.Filter += UserFilter; }
private void GridViewColumnHeaderClick(object sender, RoutedEventArgs e) { GridViewColumnHeader column = (sender as GridViewColumnHeader); sortingColumn = column; string sortBy = column.Tag.ToString(); if (listViewSortCol != null) { AdornerLayer.GetAdornerLayer(listViewSortCol).Remove(listViewSortAdorner); contractorList.Items.SortDescriptions.Clear(); } ListSortDirection newDir = ListSortDirection.Ascending; if (listViewSortCol == column && listViewSortAdorner.Direction == newDir) { newDir = ListSortDirection.Descending; } listViewSortCol = column; listViewSortAdorner = new SortAdorner(listViewSortCol, newDir); AdornerLayer.GetAdornerLayer(listViewSortCol).Add(listViewSortAdorner); var tempItems = items.ToArray(); if (sortBy == "contractorId") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, (ListViewItem a, ListViewItem b) => ((ListItem)a.Content).contractorId.CompareTo(((ListItem)b.Content).contractorId)); } else { Array.Sort(tempItems, (ListViewItem a, ListViewItem b) => ((ListItem)b.Content).contractorId.CompareTo(((ListItem)a.Content).contractorId)); } } else if (sortBy == "name") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, (ListViewItem a, ListViewItem b) => ((ListItem)a.Content).name.CompareTo(((ListItem)b.Content).name)); } else { Array.Sort(tempItems, (ListViewItem a, ListViewItem b) => ((ListItem)b.Content).name.CompareTo(((ListItem)a.Content).name)); } } else if (sortBy == "startDate") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, (ListViewItem a, ListViewItem b) => ((ListItem)a.Content).startDate.CompareTo(((ListItem)b.Content).startDate)); } else { Array.Sort(tempItems, (ListViewItem a, ListViewItem b) => ((ListItem)b.Content).startDate.CompareTo(((ListItem)a.Content).startDate)); } } else if (sortBy == "endDate") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, (ListViewItem a, ListViewItem b) => { var aa = (ListItem)a.Content; var bb = (ListItem)b.Content; if (aa.endDate == null) { return(1); } if (bb.endDate == null) { return(-1); } return(aa.endDate.Value.CompareTo(bb.endDate.Value)); }); } else { Array.Sort(tempItems, (ListViewItem a, ListViewItem b) => { var aa = (ListItem)a.Content; var bb = (ListItem)b.Content; if (bb.endDate == null) { return(1); } if (aa.endDate == null) { return(-1); } return(bb.endDate.Value.CompareTo(aa.endDate.Value)); }); } } contractorList.ItemsSource = tempItems; contractorList.Items.Refresh(); }
private void GridViewColumnHeader_Click(object sender, RoutedEventArgs e) { { GridViewColumnHeader column = (sender as GridViewColumnHeader); string sortBy = column.Tag.ToString(); if (listViewSortCol != null) { AdornerLayer.GetAdornerLayer(listViewSortCol).Remove(listViewSortAdorner); ListViewMyReservations.Items.SortDescriptions.Clear(); } ListSortDirection newDir = ListSortDirection.Ascending; if (listViewSortCol == column && listViewSortAdorner.Direction == newDir) { newDir = ListSortDirection.Descending; } listViewSortCol = column; listViewSortAdorner = new SortAdorner(listViewSortCol, newDir); AdornerLayer.GetAdornerLayer(listViewSortCol).Add(listViewSortAdorner); var tempItems = items.ToArray(); if (sortBy == "ReservationId") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareReservationByIdAscending); } else { Array.Sort(tempItems, CompareReservationByIdDescending); } } else if (sortBy == "DateStart") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareReservationByDateStartAscending); } else { Array.Sort(tempItems, CompareReservationByDateStartDescending); } } else if (sortBy == "DateEnd") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareReservationByDateEndAscending); } else { Array.Sort(tempItems, CompareReservationByDateEndDescending); } } else if (sortBy == "DateReservation") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, ComparePeopleByDateReservationAscending); } else { Array.Sort(tempItems, ComparePeopleByDateReservationDescending); } } else if (sortBy == "Car") { if (newDir.ToString() == "Ascending") { Array.Sort(tempItems, CompareCarAscending); } else { Array.Sort(tempItems, CompareCarDescending); } } ListViewMyReservations.ItemsSource = tempItems; CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(ListViewMyReservations.ItemsSource); view.Filter += UserFilter; } int CompareReservationByIdAscending(ListViewItem a, ListViewItem b) { MyReservationList first = (MyReservationList)a.Content; MyReservationList second = (MyReservationList)b.Content; return(first.ReservationId.CompareTo(second.ReservationId)); } int CompareReservationByIdDescending(ListViewItem a, ListViewItem b) { MyReservationList first = (MyReservationList)a.Content; MyReservationList second = (MyReservationList)b.Content; return(second.ReservationId.CompareTo(first.ReservationId)); } int CompareCarAscending(ListViewItem a, ListViewItem b) { MyReservationList first = (MyReservationList)a.Content; MyReservationList second = (MyReservationList)b.Content; return(String.Compare(first.Vehicle, second.Vehicle)); } int CompareCarDescending(ListViewItem a, ListViewItem b) { MyReservationList first = (MyReservationList)a.Content; MyReservationList second = (MyReservationList)b.Content; return(String.Compare(second.Vehicle, first.Vehicle)); } int CompareReservationByDateStartAscending(ListViewItem a, ListViewItem b) { MyReservationList first = (MyReservationList)a.Content; MyReservationList second = (MyReservationList)b.Content; DateTime firstDate; DateTime secondDate; if (first.ReservationStart.CompareTo("") != 0) { firstDate = Convert.ToDateTime(first.ReservationStart); } else { firstDate = DateTime.MinValue; } if (second.ReservationStart.CompareTo("") != 0) { secondDate = Convert.ToDateTime(second.ReservationStart); } else { secondDate = DateTime.MinValue; } return(DateTime.Compare(firstDate, secondDate)); } int CompareReservationByDateStartDescending(ListViewItem a, ListViewItem b) { MyReservationList first = (MyReservationList)a.Content; MyReservationList second = (MyReservationList)b.Content; DateTime firstDate; DateTime secondDate; if (first.ReservationStart.CompareTo("") != 0) { firstDate = Convert.ToDateTime(first.ReservationStart); } else { firstDate = DateTime.MinValue; } if (second.ReservationStart.CompareTo("") != 0) { secondDate = Convert.ToDateTime(second.ReservationStart); } else { secondDate = DateTime.MinValue; } return(DateTime.Compare(secondDate, firstDate)); } int CompareReservationByDateEndAscending(ListViewItem a, ListViewItem b) { MyReservationList first = (MyReservationList)a.Content; MyReservationList second = (MyReservationList)b.Content; DateTime firstDate; DateTime secondDate; if (first.ReservationEnd.CompareTo("") != 0) { firstDate = Convert.ToDateTime(first.ReservationEnd); } else { firstDate = DateTime.MinValue; } if (second.ReservationEnd.CompareTo("") != 0) { secondDate = Convert.ToDateTime(second.ReservationEnd); } else { secondDate = DateTime.MinValue; } return(DateTime.Compare(firstDate, secondDate)); } int CompareReservationByDateEndDescending(ListViewItem a, ListViewItem b) { MyReservationList first = (MyReservationList)a.Content; MyReservationList second = (MyReservationList)b.Content; DateTime firstDate; DateTime secondDate; if (first.ReservationEnd.CompareTo("") != 0) { firstDate = Convert.ToDateTime(first.ReservationEnd); } else { firstDate = DateTime.MinValue; } if (second.ReservationEnd.CompareTo("") != 0) { secondDate = Convert.ToDateTime(second.ReservationEnd); } else { secondDate = DateTime.MinValue; } return(DateTime.Compare(secondDate, firstDate)); } int ComparePeopleByDateReservationAscending(ListViewItem a, ListViewItem b) { MyReservationList first = (MyReservationList)a.Content; MyReservationList second = (MyReservationList)b.Content; DateTime firstDate; DateTime secondDate; if (first.ReservationDate.CompareTo("") != 0) { firstDate = Convert.ToDateTime(first.ReservationDate); } else { firstDate = DateTime.MinValue; } if (second.ReservationDate.CompareTo("") != 0) { secondDate = Convert.ToDateTime(second.ReservationDate); } else { secondDate = DateTime.MinValue; } return(DateTime.Compare(firstDate, secondDate)); } int ComparePeopleByDateReservationDescending(ListViewItem a, ListViewItem b) { MyReservationList first = (MyReservationList)a.Content; MyReservationList second = (MyReservationList)b.Content; DateTime firstDate; DateTime secondDate; if (first.ReservationDate.CompareTo("") != 0) { firstDate = Convert.ToDateTime(first.ReservationDate); } else { firstDate = DateTime.MinValue; } if (second.ReservationDate.CompareTo("") != 0) { secondDate = Convert.ToDateTime(second.ReservationDate); } else { secondDate = DateTime.MinValue; } return(DateTime.Compare(secondDate, firstDate)); } }