SfComboBox not updating properly

Hi,

I'm trying to use the SfComboBox in "token" mode using a dynamic List<TAttachment> data source. This is for a simple email application collecting attachments, similar to how Outlook works.

I start by setting the AttachmentsComboBox.DataSource to an empty list. When the user clicks the Browse button to select the file(s), the list is updated with the selected file(s), and the DataSource is set to the updated list. Also, the objects are added to SelectedItems.

The problem is when I remove (or unselect) items: there is no event that is fired when this happens. I've tried SelectedIndexChanged, SelectedValueChanged, and TextChanged. If I add more items to the list, it just grows because I don't have a built-in mechanism to allow changes to the list.

Please check this out. If there is a better way to go, let me know. I may revert to a ListBox until I get this resolved.

Thanks,
Kevin

Attachment: MiniMail_ee1df6a9.zip

3 Replies 1 reply marked as answer

VR Vijayalakshmi Roopkumar Syncfusion Team October 27, 2020 10:24 AM UTC

Hi Kevin, 
 
Thank you for using our syncfusion products. 
 
Query : The problem is when I remove (or unselect) items: there is no event that is fired when this happens. I've tried SelectedIndexChanged, SelectedValueChanged, and TextChanged. If I add more items to the list, it just grows because I don't have a built-in mechanism to allow changes to the list. 
 
We have checked your query and try to run your sample, but it shows the following exception. 
 
 
 
 
However from your update, we could understand that you want the event to handle on selecting and unselecting the item when SfCombobox is in MultiselectionMode. You can achieve this requirement using the following event “ItemChecked” and “ItemChecking” event of SfComboBox ‘s DropDownListView. Please find the following code and simple sample that demonstrates the same. 
 
 
Code:[C#] 
 
   
//Handle the selection and unselection of items of MultiselectionMode 
this.sfComboBox.DropDownListView.ItemChecking += DropDownListView_ItemChecking; 
this.sfComboBox.DropDownListView.ItemChecked += DropDownListView_ItemChecked; 
 
 
 
//ItemChecking event to Fire on selection in MultiselectionMode 
private void DropDownListView_ItemChecking(object sender, Syncfusion.WinForms.ListView.Events.ItemCheckingEventArgs e) 
{ 
MessageBox.Show((e.ItemData as Details).Name.ToString()); 
} 
 
 
//ItemChecked event to Fire on selection in MultiselectionMode 
private void DropDownListView_ItemChecked(object sender, Syncfusion.WinForms.ListView.Events.ItemCheckedEventArgs e) 
{ 
if(e.NewState==CheckState.Unchecked) 
{ 
MessageBox.Show("Items are removed"); 
} 
} 
 
 
 
 
Please try our solution and let us know if it is helpful at your end. 
 
Regards, 
Vijayalakshmi VR  


Marked as answer

RC Roger Criebaum October 27, 2020 02:01 PM UTC

Thanks for the demo. Two things:

1. This demo is using version 17.4.0.55 of the library. I'm using 18.3.0.42.
2. The demo works when not using tokens. Once I enable tokens (sfComboBox.EnableToken = true), it does not work. The events are not fired.

Kevin


VR Vijayalakshmi Roopkumar Syncfusion Team October 28, 2020 07:08 AM UTC

Hi Kevin, 
 
Thank you for your update. 
 
Query : The events are not fired when EnableToken is set as False. 
 
When we set the EnableToken property , the SelectedItems property holds the tokens collection. So in order to notify the collection change in SfComboBox , you can use the CollectionChanged event . Please find the following code below: 
 
Code: 
 
this.sfComboBox.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged; 
        } 
 
        // CollectionChanged event of SelectedItems to notify adding and removal of items 
        private void SelectedItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
        { 
          if(e.NewItems == null) 
            { 
                MessageBox.Show("items removed"); 
            } 
        } 
 
 
 
 
Please try this suggestion and let us know if it is helpful. 
 
Regards, 
Vijayalakshmi VR 


Loader.
Up arrow icon