-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathComboBoxExt.cs
103 lines (98 loc) · 3.88 KB
/
ComboBoxExt.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#region Copyright Syncfusion® Inc. 2001-2025.
// Copyright Syncfusion® Inc. 2001-2025. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// licensing@syncfusion.com. Any infringement will be prosecuted under
// applicable laws.
#endregion
using Syncfusion.Windows.Tools.Controls;
using System.Collections.ObjectModel;
using System.Windows;
namespace syncfusion.dropdowndemos.wpf
{
/// <summary>
/// Class represents the ComboBoxExt.
/// </summary>
public class ComboBoxExt : ComboBoxAdv
{
/// <summary>
/// Initializes a new instance of the <see cref="ComboBoxExt"/> class.
/// </summary>
public ComboBoxExt()
{
SetResourceReference(StyleProperty, typeof(ComboBoxAdv));
}
/// <summary>
/// Handle the selected items when the item is checked.
/// </summary>
/// <param name="checkedItem">Specifies the checked items in comboBox.</param>
/// <param name="selectedItems">Specifies the selected items in comboBox.</param>
/// <returns></returns>
protected override ObservableCollection<object> OnItemChecked(object checkedItem, ObservableCollection<object> selectedItems)
{
var item = ((FrameworkElement)checkedItem).DataContext;
if (item == this.Items[0])
{
AddItem(selectedItems, new int[] { 1, 2 });
}
if (item == this.Items[4])
{
AddItem(selectedItems, new int[] { 5, 6 });
}
if (item == this.Items[7])
{
AddItem(selectedItems, new int[] { 8, 9 });
}
return base.OnItemChecked(checkedItem, selectedItems);
}
/// <summary>
/// Handle the selected items when the item is unchecked.
/// </summary>
/// <param name="unCheckedItem">Specifies the unchecked items in comboBox.</param>
/// <param name="selectedItems">Specifies the selected items in comboBox.</param>
/// <returns></returns>
protected override ObservableCollection<object> OnItemUnchecked(object uncheckedItem, ObservableCollection<object> selectedItems)
{
var item = ((FrameworkElement)uncheckedItem).DataContext;
if (item == this.Items[0])
{
RemoveItem(selectedItems, new int[] { 1, 2 });
}
if (item == this.Items[4])
{
RemoveItem(selectedItems, new int[] { 5, 6 });
}
if (item == this.Items[7])
{
RemoveItem(selectedItems, new int[] { 8, 9 });
}
return base.OnItemUnchecked(uncheckedItem, selectedItems);
}
/// <summary>
/// Method used to check the items in comboBox.
/// </summary>
/// <param name="selectedItems">Specifies the selected items in comboBox.</param>
/// <param name="index">Specifies the index of items.</param>
public void AddItem(ObservableCollection<object> selectedItems, int[] index)
{
foreach (int i in index)
{
if (!selectedItems.Contains(this.Items[i]))
selectedItems.Add(this.Items[i]);
}
}
/// <summary>
/// Method used to uncheck the items in comboBox.
/// </summary>
/// <param name="selectedItems">Specifies the selected items in comboBox.</param>
/// <param name="index">Specifies the index of items.</param>
public void RemoveItem(ObservableCollection<object> selectedItems, int[] index)
{
foreach (int i in index)
{
if (selectedItems.Contains(this.Items[i]))
selectedItems.Remove(this.Items[i]);
}
}
}
}