Skip to content

Commit 6d85c7f

Browse files
authored
Update README.md
1 parent 6c79453 commit 6d85c7f

1 file changed

Lines changed: 90 additions & 43 deletions

File tree

README.md

Lines changed: 90 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,117 @@
1-
# WPF-ComboBoxAdv-MultiSelection
2-
This repository contains the sample that how to select the items programmatically in WPF ComboBoxAdv.
1+
# WPF ComboBoxAdv MultiSelection
2+
This repository demonstrates how to select items programmatically in the Syncfusion WPF ComboBoxAdv control and enable multi-selection functionality.
33

4-
# Creating project
5-
Below section provides detailed information to create new project in Visual Studio to display ComboBoxAdv.
6-
# Adding control manually in XAML
7-
In order to add ComboBoxAdv control manually in XAML, do the below steps,
4+
## Why Use ComboBoxAdv MultiSelection?
5+
- Allows users to select multiple items from a dropdown list.
6+
- Supports data binding for dynamic item updates.
7+
- Ideal for scenarios like filtering, tagging, or multi-choice forms.
88

9-
1. Add the below required assembly references to the project,
9+
## Creating project
10+
Follow these steps to create a new WPF project in Visual Studio and add the ComboBoxAdv control:
1011

11-
* Syncfusion.Shared.WPF
12-
2. Import Syncfusion WPF schema http://schemas.syncfusion.com/wpf in XAML page or Syncfusion.Windows.Tools.Controls namespace.
12+
### Adding Control Manually in XAML
1313

14-
3. Declare ComboBoxAdv in XAML page.
15-
**[XAML]**
14+
1. Add the required assembly reference:
15+
- Syncfusion.Shared.WPF
1616

17+
2. Import the Syncfusion WPF schema:
18+
```XAML
19+
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
1720
```
18-
<Grid>
19-
<syncfusion:ComboBoxAdv Height="30" Width="150"/>
20-
</Grid>
21-
```
22-
23-
# Adding control manually in C#
24-
In order to add ComboBoxAdv control manually in C#, do the below steps,
25-
26-
1. Add the below required assembly references to the project,
27-
28-
* Syncfusion.Shared.WPF
2921

30-
2. Import ComboBoxAdv namespace Syncfusion.Windows.Tools.Controls.
22+
3. Declare the ComboBoxAdv in XAML:
23+
```XAML
24+
<Grid>
25+
<syncfusion:ComboBoxAdv Height="30" Width="150"/>
26+
</Grid>
27+
```
3128

32-
3. Create ComboBoxAdv control instance and add it to the page.
29+
### Adding Control Manually in C#
3330

31+
1. Add the required assembly reference:
32+
- Syncfusion.Shared.WPF
3433

35-
**[C#]**
34+
2. Import the namespace:
35+
```C#
36+
using Syncfusion.Windows.Tools.Controls;
3637
```
38+
39+
3. Create and configure the ComboBoxAdv instance:
40+
```C#
3741
public partial class MainWindow : Window
3842
{
3943
public MainWindow()
4044
{
4145
InitializeComponent();
42-
ComboBoxAdv comboBoxAdv = new ComboBoxAdv();
46+
ComboBoxAdv comboBoxAdv = new ComboBoxAdv
47+
{
48+
Height = 30,
49+
Width = 150,
50+
DefaultText = "Choose Items"
51+
};
4352
this.Content = comboBoxAdv;
44-
comboBoxAdv.Height = 30;
45-
comboBoxAdv.Width = 150;
46-
comboBoxAdv.DefaultText = "choose Items";
4753
}
4854
}
4955
```
50-
# ComboBoxAdv MultiSelection
56+
## ComboBoxAdv MultiSelection Example
57+
Enable multi-selection and bind data using MVVM:
5158

5259
**[XAML]**
53-
54-
```
55-
<syncfusion:ComboBoxAdv DisplayMemberPath="Name"
56-
SelectedItems="{Binding SelectedItems, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
57-
AllowMultiSelect="True" Name="comboboxadv" HorizontalAlignment="Center" Height="30"
58-
VerticalAlignment="Center" Width="150" ItemsSource="{Binding Countries}"/>
60+
```XAML
61+
<Window.DataContext>
62+
<local:ViewModel />
63+
</Window.DataContext>
64+
65+
<Grid>
66+
<syncfusion:ComboBoxAdv DisplayMemberPath="Name"
67+
SelectedItems="{Binding SelectedItems, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
68+
AllowMultiSelect="True"
69+
Name="comboboxadv"
70+
HorizontalAlignment="Center"
71+
Height="30"
72+
VerticalAlignment="Center"
73+
Width="150"
74+
ItemsSource="{Binding Countries}"/>
75+
</Grid>
5976
```
60-
## How to run this application?
77+
**ViewModel**
78+
```C#
79+
public class ViewModel : INotifyPropertyChanged
80+
{
81+
private ObservableCollection<object> selectedItems;
82+
public ObservableCollection<object> SelectedItems
83+
{
84+
get => selectedItems;
85+
set
86+
{
87+
selectedItems = value;
88+
RaisePropertyChanged(nameof(SelectedItems));
89+
}
90+
}
6191

62-
To run this application, you need to first clone the WPF-ComboBoxAdv-MultiSelection repository and then open it in Visual Studio 2022. Now, simply build and run your project to view the output.
92+
public ObservableCollection<Country> Countries { get; set; }
6393

64-
## <a name="troubleshooting"></a>Troubleshooting ##
65-
### Path too long exception
66-
If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.
94+
public ViewModel()
95+
{
96+
Countries = new ObservableCollection<Country>
97+
{
98+
new Country() { Name = "Denmark" },
99+
new Country() { Name = "New Zealand" },
100+
new Country() { Name = "Canada" },
101+
new Country() { Name = "Russia" },
102+
new Country() { Name = "Japan" }
103+
};
104+
105+
SelectedItems = new ObservableCollection<object>(Countries.Take(2));
106+
}
67107

68-
## License
108+
public event PropertyChangedEventHandler PropertyChanged;
109+
private void RaisePropertyChanged(string propertyName)
110+
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
111+
}
69112

70-
Syncfusion has no liability for any damage or consequence that may arise by using or viewing the samples. The samples are for demonstrative purposes, and if you choose to use or access the samples, you agree to not hold Syncfusion liable, in any form, for any damage that is related to use, for accessing, or viewing the samples. By accessing, viewing, or seeing the samples, you acknowledge and agree Syncfusion’s samples will not allow you seek injunctive relief in any form for any claim related to the sample. If you do not agree to this, do not view, access, utilize, or otherwise do anything with Syncfusion’s samples.
113+
public class Country
114+
{
115+
public string Name { get; set; }
116+
}
117+
```

0 commit comments

Comments
 (0)