Back to Devexpress

ListBoxItemClickEventArgs<TData, TValue>.InputDevice Property

blazor-devexpress-dot-blazor-dot-listboxitemclickeventargs-2-a0906481.md

latest5.0 KB
Original Source

ListBoxItemClickEventArgs<TData, TValue>.InputDevice Property

Returns the input device that triggered the event.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public InputDevice InputDevice { get; }

Property Value

TypeDescription
InputDevice

The input device that triggered the event.

|

Available values:

NameDescription
Pointer

A pointing device.

| | Keyboard |

A keyboard.

|

Remarks

You can handle the ItemClick event in response to the following actions:

  • A user clicks a list box item with a pointing device.
  • A user focuses a list box item with keyboard navigation (↑/↓ keys) and presses Enter.

Use the InputDevice event argument to determine which action triggered the ItemClick event.

Note

By default, the List Box triggers item selection when a user clicks an item or focuses it and presses the Space key. You can handle the ItemClick event to also treat Enter as a selection key.

The following code determines which action triggers the ItemClick event. If a user presses the Enter key, the List Box selects the corresponding item.

razor
<DxListBox Data="@Staff.DataSource"
           TData="Person"
           TValue="Person"
           @bind-Value="ListBoxValue"
           ItemClick="@OnItemClick">
    <Columns>
        <DxListEditorColumn FieldName="@nameof(Person.FirstName)" Caption="First Name" />
        <DxListEditorColumn FieldName="@nameof(Person.LastName)" Caption="Last Name" />
        <DxListEditorColumn FieldName="@nameof(Person.Department)" />
    </Columns>
</DxListBox>

@code {
    Person ListBoxValue;

    void OnItemClick(ListBoxItemClickEventArgs<Person, Person> args) {
        if (args.InputDevice == InputDevice.Keyboard) {
            args.ListBox.BeginUpdate();
            args.ListBox.Value = args.DataItem;
            args.ListBox.EndUpdate();
        }
    }
}
cs
namespace StaffData {
    public static class Staff {
        private static readonly Lazy<List<Person>> dataSource = new Lazy<List<Person>>(() => {
            var dataSource = new List<Person>() {
                new Person() { Id = 0 , FirstName = "John", LastName = "Heart", Department=Department.Electronics },
                new Person() { Id = 1 , FirstName = "Samantha", LastName = "Bright", Department=Department.Motors },
                new Person() { Id = 2 , FirstName = "Arthur", LastName = "Miller", Department=Department.Software },
                new Person() { Id = 3 , FirstName = "Robert", LastName = "Reagan", Department=Department.Electronics },
                new Person() { Id = 4 , FirstName= "Greta", LastName = "Sims", Department=Department.Motors },
                new Person() { Id = 5 , FirstName = "Brett", LastName = "Wade", Department=Department.Software },
                new Person() { Id = 6 , FirstName = "Sandra", LastName = "Johnson", Department=Department.Electronics },
                new Person() { Id = 7 , FirstName = "Edward", LastName = "Holmes", Department=Department.Motors },
                new Person() { Id = 8 , FirstName = "Barbara", LastName = "Banks", Department=Department.Software },
                new Person() { Id = 9 , FirstName = "Kevin", LastName = "Carter", Department=Department.Electronics }, 
                new Person() { Id = 10, FirstName = "Cynthia", LastName = "Stanwick", Department=Department.Motors },
                new Person() { Id = 11, FirstName = "Sam", LastName = "Hill", Department=Department.Electronics }};
            return dataSource;
        });
        public static List<Person> DataSource { get { return dataSource.Value; } }
    }

    public class Person {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public Department Department { get; set; }
        public string Text => $"{FirstName} {LastName} ({Department} Dept.)";
        public override bool Equals(object obj) {
            if (obj is Person typedObj) {
                return (this.Id == typedObj.Id) && (this.FirstName == typedObj.FirstName) && (this.LastName == typedObj.LastName)
                && (this.Department == typedObj.Department);
            }
            return base.Equals(obj);
        }
        public override int GetHashCode() {
            return HashCode.Combine(Id, FirstName, LastName);
        }
    }

    public enum Department { Motors, Electronics, Software }
}

See Also

ListBoxItemClickEventArgs<TData, TValue> Class

ListBoxItemClickEventArgs<TData, TValue> Members

DevExpress.Blazor Namespace