JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › ComboBox › MultiComboInput
Tagged: MultiComboInput
- This topic has 2 replies, 2 voices, and was last updated 1 year, 6 months ago by
xyzzy.
-
AuthorPosts
-
September 16, 2021 at 11:11 pm #102211
xyzzy
MemberHi,
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)
{
???
}
ThanksSeptember 17, 2021 at 8:31 am #102213YavorDashev
MemberHi 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/September 17, 2021 at 2:22 pm #102219xyzzy
MemberThanks. 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. -
AuthorPosts
- You must be logged in to reply to this topic.