Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #102211
    xyzzy
    Member

    Hi,
    I need to detect what items (check boxes) are clicked.  I have tried using the OnChange event but there doesn’t seem to be any means of determining what the change was.  Could you advise on the event to use and provide a code sample on how to extract the item that was checked or unchecked, or the current status of the list of checkboxes in the control?
    <MultiComboInput OnChange=@cboFormula_Change DataSource=@cboFormula SelectedIndexes=@cboFormula_SelectedItem DisplayMember=”label” ValueMember=”value”>
    private void cboFormula_Change(Event eventObj)
    {
    ???
    }
    Thanks

    #102213
    YavorDashev
    Member

    Hi xyzzy,
    I have created a quick code snippet so that I can showcase you how to have the functionality that you need.

    div @ref="divRef" style="height:1000px">
     <MultiComboInput DropDownButtonPosition="DropDownButtonPosition.Right" OnChange="@ChangeEmit" DataSource="@summaries"></MultiComboInput>
    </div>
    @code {
        private void ChangeEmit (Event EventObj)
        {
            var detail = EventObj["detail"];
            Console.WriteLine(detail);
        }
    

    Let me know if that works for you!
    Please, do not hesitate to contact us if you have any additional questions.
    Best regards,
    Yavor Dashev
    Smart UI Team
    https://www.htmlelements.com/

    #102219
    xyzzy
    Member

    Thanks.  For others looking at this post the solution is:
    private void cboFormula_Change(Event eventObj)
    {
    MultiComboInputChangeEventDetail detail = eventObj[“Detail”];
    if (detail.Value != detail.OldValue)  //Redundant as fires when an item is clicked or unclicked therefore always a change
    {
    string csv = detail.Value;
    csv = csv.Replace(” “, “”);  //The returned array is 0, 1, 4, 6 – so has a space after each comma
    var items = csv.Split(‘,’)
    .Where(m => int.TryParse(m, out _))
    .Select(m => int.Parse(m))
    .ToList();
    myBooleanSetting = items.Contains(0);
    …. (repeat for each item)
    }
    }
    You get four properties in the event object:
    Value – CSV string of integer values (post-change)
    OldValue – CSV string of integer values (pre-change)
    And similar with the text strings of the items: Label and OldLabel
    If you have a long list best option is to compare the OldValue and Value to see what changed.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.