From 97aaa6a50e3038741ade19c88f9d3b4c9ef407a2 Mon Sep 17 00:00:00 2001 From: KrithikaGanesan Date: Mon, 27 Oct 2025 12:01:09 +0530 Subject: [PATCH 1/2] 985360: Updated ReadMe file of this repository --- README.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bf71dfc..93e3e09 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ -# How-to-programmatically-select-all-DropDownItems-in-SfComboBox -This repository contains the sample that how to programmatically select all DropDownItems in SfComboBox +# How to Programmatically Select All DropDownItems in SfComboBox +This repository demonstrates how to programmatically select all items in the DropDown list of the Syncfusion SfComboBox control in a Windows Forms application. The SfComboBox is a powerful UI component that supports advanced features like multi-selection, auto-complete, and data binding. In scenarios where you need to select all items at once—such as applying bulk actions or initializing default selections—this sample provides a clear and practical approach. + +## Key Features Demonstrated in This Sample + • Enable multi-selection mode in SfComboBox. + • Programmatically select all items in the DropDown list using the SelectedItems collection. + • Handle scenarios where the data source is dynamically loaded. + • Ensure the UI reflects the selection state immediately after applying changes. + +## Steps to Select All Items Programmatically + 1. Set the ComboBoxMode property to MultiSelection to allow multiple selections. + 2. Access the SelectedItems property and add all items from the data source. + 3. Refresh the control to update the UI. + +This approach ensures that all items in the DropDown are selected without requiring manual user interaction. It is particularly useful for applications that need to apply global settings or perform batch operations. From fee8f944ea661e46f318745cc1671132de0c0bd4 Mon Sep 17 00:00:00 2001 From: Manivannan-E <92844213+Manivannan-E@users.noreply.github.com> Date: Thu, 27 Nov 2025 13:04:27 +0530 Subject: [PATCH 2/2] Update README.md --- README.md | 110 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 95 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 93e3e09..0cbb044 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,95 @@ -# How to Programmatically Select All DropDownItems in SfComboBox -This repository demonstrates how to programmatically select all items in the DropDown list of the Syncfusion SfComboBox control in a Windows Forms application. The SfComboBox is a powerful UI component that supports advanced features like multi-selection, auto-complete, and data binding. In scenarios where you need to select all items at once—such as applying bulk actions or initializing default selections—this sample provides a clear and practical approach. - -## Key Features Demonstrated in This Sample - • Enable multi-selection mode in SfComboBox. - • Programmatically select all items in the DropDown list using the SelectedItems collection. - • Handle scenarios where the data source is dynamically loaded. - • Ensure the UI reflects the selection state immediately after applying changes. - -## Steps to Select All Items Programmatically - 1. Set the ComboBoxMode property to MultiSelection to allow multiple selections. - 2. Access the SelectedItems property and add all items from the data source. - 3. Refresh the control to update the UI. - -This approach ensures that all items in the DropDown are selected without requiring manual user interaction. It is particularly useful for applications that need to apply global settings or perform batch operations. +# How to Programmatically Select All DropDown Items in WinForms SfComboBox +This example demonstrates how to programmatically select all items in the Syncfusion WinForms SfComboBox control. The SfComboBox supports advanced features like multi-selection, auto-complete, and data binding. Selecting all items programmatically is useful for scenarios such as applying bulk actions or initializing default selections. + +## Why This Is Useful +- **Batch Operations**: Apply global settings to all items. +- **Default Selections**: Pre-select all items when loading data. +- **Improved UX**: Avoid manual selection for large lists. + +## Key Steps +- Set _ComboBoxMode_ to MultiSelection to allow multiple selections. +- Bind the data source to the SfComboBox. +- Iterate through all items and add them to _CheckedItems_ collection. +- Refresh the UI to reflect the changes. + +## Code example + +**Designer** +```C# +#region Windows Form Designer generated code +private void InitializeComponent() +{ + this.sfComboBox1 = new Syncfusion.WinForms.ListView.SfComboBox(); + this.button1 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.sfComboBox1)).BeginInit(); + this.SuspendLayout(); + + // sfComboBox1 + this.sfComboBox1.Location = new System.Drawing.Point(445, 143); + this.sfComboBox1.Name = "sfComboBox1"; + this.sfComboBox1.Size = new System.Drawing.Size(257, 57); + this.sfComboBox1.TabIndex = 0; + + // button1 + this.button1.Location = new System.Drawing.Point(33, 162); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(211, 38); + this.button1.Text = "Select Programmatically"; + this.button1.Click += new System.EventHandler(this.button1_Click); + + // Form1 + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button1); + this.Controls.Add(this.sfComboBox1); + this.Text = "SfComboBox_CheckedItems"; + + ((System.ComponentModel.ISupportInitialize)(this.sfComboBox1)).EndInit(); + this.ResumeLayout(false); +} +#endregion +``` + +**Logic** +```C# + +public Form1() +{ + InitializeComponent(); + + // Bind data source + sfComboBox1.DataSource = GetTable(); + sfComboBox1.DisplayMember = "Patient"; + sfComboBox1.ValueMember = "Drug"; + sfComboBox1.ComboBoxMode = ComboBoxMode.MultiSelection; + this.StartPosition = FormStartPosition.CenterScreen; +} + +private static DataTable GetTable() +{ + DataTable table = new DataTable(); + table.Columns.Add("Dosage", typeof(int)); + table.Columns.Add("Drug", typeof(string)); + table.Columns.Add("Patient", typeof(string)); + table.Columns.Add("Date", typeof(DateTime)); + + table.Rows.Add(25, "Indocin", "David", DateTime.Now); + table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now); + table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now); + table.Rows.Add(21, "Combivent", "Janet", DateTime.Now); + table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now); + return table; +} + +private void button1_Click(object sender, EventArgs e) +{ + foreach (var item in sfComboBox1.DropDownListView.View.Items.ToList()) + { + sfComboBox1.DropDownListView.CheckedItems.Add(item); + } +} +``` + +## Notes +- Ensure ComboBoxMode is set to MultiSelection for multiple selections. +- Use CheckedItems collection to programmatically select items. +- This approach works for both static and dynamic data sources.