Skip to main content

DataGridView.SelectedItem Property

Returns an object that specifies the data source record to which the currently selected data row in the grid corresponds. This is a bindable property.

Namespace: DevExpress.Maui.DataGrid

Assembly: DevExpress.Maui.DataGrid.dll

NuGet Package: DevExpress.Maui.DataGrid

Declaration

public object SelectedItem { get; set; }

Property Value

Type Description
Object

An object that specifies an individual record of a data source bound to the grid.

Remarks

When a user taps a data row in the grid, that row becomes selected.

Grid Data Rows

To obtain the handle of the grid’s selected data row, use the SelectedRowHandle property. After the grid’s selection is changed, the DataGridView.SelectionChanged event occurs.

To prevent users from selecting rows, set the SelectionMode property to SelectionMode.None.

The following example specifies the selected item in the grid:

<ContentPage.BindingContext>
    <local:EmployeeDataViewModel/>
</ContentPage.BindingContext>
<dx:DataGridView ...
                 SelectedItem="{Binding SelectedEmployee}">
      <!--...-->
</dx:DataGridView>
public class EmployeeDataViewModel : INotifyPropertyChanged {
    readonly EmployeeData data;
    public event PropertyChangedEventHandler PropertyChanged;
    public IReadOnlyList<Employee> Employees { get => data.Employees; }
    public Employee SelectedEmployee { get => data.Employees.First(x => x.Name.Contains("Janet")); }
    public EmployeeDataViewModel() {
        data = new EmployeeData();
    }
    protected void RaisePropertyChanged(string name) {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(name));
    }
}
See Also