Skip to content

Commit cc17096

Browse files
authored
Merge pull request #3 from DuraimuruganVedagiri/master
WF-54532
2 parents aa86b02 + 47ce20b commit cc17096

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

SfComboBox/SfComboBox/Form1.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SfComboBox/SfComboBox/Form1.cs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
using Syncfusion.WinForms.ListView;
1+
using Syncfusion.WinForms.ListView.Enums;
22
using System;
33
using System.Collections.Generic;
4-
using System.ComponentModel;
5-
using System.Data;
64
using System.Drawing;
7-
using System.Linq;
8-
using System.Text;
9-
using System.Threading.Tasks;
105
using System.Windows.Forms;
116

127
namespace SfComboBox
@@ -22,32 +17,33 @@ public Form1()
2217

2318
private void DropDownListView_SelectionChanged(object sender, Syncfusion.WinForms.ListView.Events.ItemSelectionChangedEventArgs e)
2419
{
25-
if (e.AddedItems.Count == this.sfComboBox.DropDownListView.View.Items.Count())
20+
if (e.AddedItems.Count == this.sfComboBox.DropDownListView.View.Items.Count)
2621
{
27-
foreach (var value in disableItems)
28-
this.sfComboBox.DropDownListView.CheckedItems.Remove(value);
22+
for (int i = 0; i < this.sfComboBox.DropDownListView.CheckedItems.Count; i++)
23+
{
24+
if ((this.sfComboBox.DropDownListView.CheckedItems[i] as Details).IsEnabled == false)
25+
this.sfComboBox.DropDownListView.CheckedItems.RemoveAt(i);
26+
}
2927
}
3028
}
3129

3230
private void DropDownListView_ItemChecking(object sender, Syncfusion.WinForms.ListView.Events.ItemCheckingEventArgs e)
3331
{
34-
bool isDisabledItem = disableItems.Contains(e.ItemData);
35-
if ((this.sfComboBox.AllowSelectAll == false && isDisabledItem) || (e.ItemIndex != 0 && isDisabledItem))
36-
{
32+
bool isItemEnable = (this.sfComboBox.ComboBoxMode == ComboBoxMode.MultiSelection && this.sfComboBox.AllowSelectAll && e.ItemIndex == 0) ? true : (e.ItemData as Details).IsEnabled;
33+
if (!isItemEnable)
3734
e.Cancel = true;
38-
}
3935
}
4036

4137
private void DropDownListView_SelectionChanging(object sender, Syncfusion.WinForms.ListView.Events.ItemSelectionChangingEventArgs e)
4238
{
43-
if (this.disableItems.Contains(e.AddedItems[0]))
39+
if (e.AddedItems.Count > 0 && !(e.AddedItems[0] as Details).IsEnabled && e.AddedItems.Count != this.sfComboBox.DropDownListView.View.Items.Count )
4440
e.Cancel = true;
4541
}
4642

4743
private void DropDownListView_DrawItem(object sender, Syncfusion.WinForms.ListView.Events.DrawItemEventArgs e)
4844
{
49-
bool isDisabledItem = disableItems.Contains(e.ItemData);
50-
if ((this.sfComboBox.AllowSelectAll == false && isDisabledItem) || (e.ItemIndex != 0 && isDisabledItem))
45+
bool isItemEnable = (this.sfComboBox.ComboBoxMode == ComboBoxMode.MultiSelection && this.sfComboBox.AllowSelectAll && e.ItemIndex == 0) ? true : (e.ItemData as Details).IsEnabled;
46+
if (!isItemEnable)
5147
{
5248
e.Style.BackColor = Color.LightGray;
5349
e.Style.ForeColor = Color.Gray;
@@ -58,21 +54,26 @@ private void DropDownListView_DrawItem(object sender, Syncfusion.WinForms.ListVi
5854

5955
#region Data Setting
6056

61-
List<string> disableItems = new List<string>() { "Asif" };
57+
public class Details
58+
{
59+
public string Name { get; set; }
60+
61+
public bool IsEnabled { get; set; } = true;
62+
}
6263

63-
public List<string> GetData()
64+
public List<Details> GetData()
6465
{
65-
List<string> list = new List<string>();
66-
list.Add("Amir");
67-
list.Add("Asif");
68-
list.Add("Catherine");
69-
list.Add("Cindrella");
70-
list.Add("David");
71-
list.Add("Ellis");
72-
list.Add("Farooq");
73-
list.Add("Muhammad");
74-
list.Add("Saleem");
75-
list.Add("Usman");
66+
List<Details> list = new List<Details>();
67+
list.Add(new Details { Name = "Amir", IsEnabled = false });
68+
list.Add(new Details { Name = "Asif" });
69+
list.Add(new Details { Name = "Catherine" });
70+
list.Add(new Details { Name = "Cindrella" });
71+
list.Add(new Details { Name = "David", IsEnabled = false });
72+
list.Add(new Details { Name = "Ellis" });
73+
list.Add(new Details { Name = "Farooq" });
74+
list.Add(new Details { Name = "Muhammad" });
75+
list.Add(new Details { Name = "Saleem" });
76+
list.Add(new Details { Name = "Usman" });
7677
return list;
7778
}
7879

0 commit comments

Comments
 (0)