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
0
IgbMultiColumnComboBox ValueChanged Event
posted

Hello!

If I have a datasource that has a field called "EntityKey" in it and I want to pass the selected item's EntityKey to a ValueChanged event, how would I do that? 

I have this as my combobox definition.

       <IgbMultiColumnComboBox Height="50px" Width="400px"
                                DataSource="entities"
                                Fields="DisplayFields"
                                TextField="Name"
                                Placeholder = "Select Entity" 
                                DefaultColumnWidth="200"
                                ValueChanged="Entity_ValueChanged(Value)"
                                Value="@CurrentEntity"
                                id="cmbEntities"
                                SortMode="SortMode.SortByMultipleColumnsTriState" />

(please note I've pasted my code into the insert - code function on the forum post editor and it does not show up unless I go in to edit it, not sure if it will show up once this is posted)

When I try to set the ValueField property of the control to ValueField = "EntityKey" it doesn't recognize this as being valid.  When I try to set the ValueChanged="Entity_ValueChanged(Value)" it doesn't recognize value.  I've tried subbing in "EntityKey" and @EntityKey for the ValueChanged parameter, but none of it works.  I just want to be able to say that the value field of my combobox is the Entity Key and the when the value changes, pass that entity key to the c# code so I can do something with it.  


Please advise. 

  • 34810
    Offline posted

    Hello Melissa,

    The ValueField and ValueChanged events are interlinked, in that the path that you provide to the ValueField will appear as the parameter for the ValueChanged event. For example, given the following class:

        public class SampleData
        {
            public string Display{ get; set; }
            public int Value{ get; set; }
        }

    Let’s say your IgbMultiColumnCombo is bound to a List<SampleData> and you want to see “Display” as the text of that combo but want to get “Value” in the ValueChanged event. You could do this like so, where “Data” is the List<SampleData>:

        <IgbMultiColumnComboBox Height="50px" Width="400px" @ref=ComboRef                          
                                DataSource="Data"
                                TextField="Display"                                                                 
                                ValueField=@(new string[]{ "Value"})
                                ValueChanged="OnValueChanged" />

    The “OnValueChanged” handler would look like the following:

        public void OnValueChanged(Object obj)
        {      
        }

    In this case, the “Object obj” parameter would be the “Value” of the SampleData item that you select when the event fires.