Sfcombobox Multiselect - Set Checked items on load (pre-checked)

Hi,

I want to mark as checked the items on form load:

So i give same type of model to CheckedItems property as sfcombobox datasource:
on load method:
            Sfcombobox .DataSource = projects.getRoadTypes();//returns EF model which type is RoadTypes
            Sfcombobox .ValueMember = "ID";
            Sfcombobox .DisplayMember = "Name";

            Sfcombobox .CheckedItems = new System.Collections.ObjectModel.ObservableCollection<object> (projects.getRoadTypes());


on debug panel, it seems checkitems are set but it is not checked visually in Sfcombobox component on form.

4 Replies

DV Duraimurugan Vedagiri Syncfusion Team March 24, 2020 11:59 AM UTC

Hi ERTEM,

Thanks for using syncfusion products.

We have analyzed the reported query "checkitems are set but it is not checked visually in Sfcombobox component" and confirmed it as a defect. We have logged a defect report on this and the patch for this fix is estimated to be available on April 7th, 2020.

You can track the status through the following feedback link:

https://www.syncfusion.com/feedback/12940/checkitems-are-set-but-it-is-not-displayed-visually-in-sfcombobox

And we suggest the workaround solution to achieve your requirement. Instead of directly set the collection, please use foreach loop to add the SfComboBox.CheckedItems collection. Please find the below sample and code snippet for your reference.

Sample link : https://www.syncfusion.com/downloads/support/forum/152619/ze/SfComboBoxSample-251506324

private void Form1_Load(object sender, EventArgs e) 
{ 
    //this.sfComboBox1.CheckedItems = new ObservableCollection<object>(this.getRoadTypes()); 
    foreach (var value in this.getRoadTypes()) 
    { 
        sfComboBox1.CheckedItems.Add(value); 
    } 
} 

Please let us know if you have any concerns.

Regards, 
Durai 



ER ERTEM March 24, 2020 10:20 PM UTC

Hi Duraimurugan ,

Actually your code sample helped a lot thanks. I have found another issue but i m unable to understand why and how it occurs.

If i use this way:
 foreach (var value in this.project.getRoadTypes())  
    { 
        sfComboBox1.CheckedItems.Add(value); 
    } 
}

The items in dropdownlist on combobox component still are not checked. getRoadTypes method returns the List<RoadTypes>. RoadTypes is EF data model which created by EF as poco class.

On the other hand if i use this way that you create on sample project it works:

        List<RoadTypes> roadTypesList = new List<RoadTypes>();
        private List<RoadTypes> GetRoadTypes()
        {
            foreach (var item in this.project.GetRoadTypes())
            {
                roadTypesList.Add(new RoadTypes() { ID = item.ID, Name= item.RoadType});
               
            }

        }
     
       GetRoadTypes()
       sfComboBox1.DataSourceroadTypesList;
            sfComboBox1.DisplayMember = "Name";
            sfComboBox1.ValueMember = "ID";

           foreach (var value in roadTypesList)
            {
                sfComboBox1.CheckedItems.Add(value);
            }


DV Duraimurugan Vedagiri Syncfusion Team March 25, 2020 03:27 PM UTC

Hi ERTEM,

Thanks for your update

Currently we are validating the reported query and will update you the further details on or before March 27th, 2020.

Regards,
Durai


DV Duraimurugan Vedagiri Syncfusion Team March 27, 2020 02:38 PM UTC

Hi ERTEM,

Thanks for your patience

We analyzed the reported query and prepared the simple sample with Entity Framework model, but we are unable to reproduced at our end. Please refer the below sample, if our replication procedure is different from your requirement kindly modify our sample with issue reproducible, it would be very helpful for us to provide the solution at earliest.

Sample : https://www.syncfusion.com/downloads/support/forum/152619/ze/SfComboBoxEF1372261360

Regards,
Durai

Loader.
Up arrow icon