Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
335
Setting multiple values on initialSelectedItems using the MVC helpers
posted

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?

Parents
  • 440
    Offline posted

    Hello,

    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")

        .MultiSelectionSettings(ms =>

        {

            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 }

        })

        .DataBind()

        .Render()

    )

    In this example:

    • .MultiSelectionSettings(ms => { ms.Enabled(true); }) ensures that multi-selection is enabled for the combo box.
    • .InitialSelectedItems(new[] { ... }) specifies the array of objects where each object defines either an index or a value to select the initial items.
    • Replace index values (0, 1, 2 in the example) with the actual indices or values from your data source that you want to be selected initially.

    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,

    Georgi Anastasov

    Entry Level Software Developer

    Infragistics

Reply Children
No Data