The ComboInitialSelectedItemsSettings object seems to only accept a single Value or single Index.I have MultiSelection enabled on my combo so I would like to set multiple inital values. How do I do this using the MVC helpers?
Hello,
Thank you for your response and for pointing out the discrepancy regarding the InitialSelectedItems method. You are correct; the ComboInitialSelectedItems does not accept an array of objects directly in the MVC API.
To achieve your requirement of setting multiple initial values in a combo box with multi-selection enabled, you can use jQuery to initialize the selected items after the combo box is rendered. Here’s how you can do it:
<div>
@(
Html.Infragistics().ComboFor(item => item.Countries)
.ID("multiCombo1")
.Width("300px")
.DataSource(Model.Countries)
.ValueKey("Key")
.TextKey("Value")
.MultiSelectionSettings(ms =>
{
ms.Enabled(true);
})
.DataBind()
.Render()
)
</div>
Combo Box Configuration:
Next, use the following script to set the initial selected items using jQuery. You can place this script within the Scripts section of your view:
@section Scripts {
<script>
$(document).ready(function () {
$("#multiCombo1").igCombo({
initialSelectedItems: [
{ value: "2" }, // Replace with the actual values or keys you want to select
{ value: "5" }
]
});
</script>
}
Script Section:
This approach should help you set multiple initial selected items in the combo box with multi-selection enabled.
If you have any further questions or need additional assistance, please feel free to reach out.
Thank you for your patience and understanding.Regards,
Georgi Anastasov
Entry Level Software Developer
Infragistics
Hello Georgi,I cannot find the InitialSelectedItems method in the MVC API. You probably mean ComboInitialSelectedItems?https://www.igniteui.com/help/infragistics.web.mvc~infragistics.web.mvc.combowrapper~comboinitialselecteditemsAccording to your documentation this does not accept an array of objects
Thank you for reaching out with your query regarding setting multiple initial selected items in the Infragistics MVC Combo box with multi-selection enabled.
To achieve this using the MVC helpers provided by Infragistics, you can utilize the InitialSelectedItems method. This method accepts an array of objects where each object specifies either an index or a value property to indicate which items should be initially selected.
Here’s an example of how you can implement this in your MVC view:
@(Html.Infragistics().ComboFor(item => item.EmployeeID)
.Width("270px")
.DataSource(Url.Action("data-source"))
.ValueKey("ID")
.TextKey("Name")
ms.Enabled(true); // Ensure multi-selection is enabled
.InitialSelectedItems(new[]
new { index = 0 }, // Replace with actual indices or values you want to select
new { index = 1 },
new { index = 2 }
In this example:
Please adjust the ValueKey and TextKey parameters to match the properties of the objects in your data source.
If you require any further assistance on the matter, please let me know.
Regards,