Unplanned
Last Updated: 17 Jan 2022 14:14 by ADMIN
Geoffrey
Created on: 17 Jan 2022 13:52
Category: DataGrid
Type: Bug Report
0
DataGrid: Selected Style is not applied when selected item is initially set
When the selected item is set initially, the selected style is not applied to the row/cell
1 comment
ADMIN
Didi
Posted on: 17 Jan 2022 14:14

Workaround: 

1) subscribe to DataGrid PropertyChanged and when the e.PropertyName is Height, set the selected item

DataGrid.PropertyChanged += DataGrid_PropertyChanged;

private void DataGrid_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        var data = sender as RadDataGrid;

        if (e.PropertyName == "Height")  
        {
            var firstItem = ((List<Person>)this.DataGrid.ItemsSource).First();
            this.DataGrid.SelectItem(firstItem);

            if (DataGrid.SelectedItem != null)
            {
                DisplayAlert("", "", "cancel");
            }
        }
    }

2) Use a dispatcher with a delay, then inside it set the selected item.

DataGrid.ItemsSource = this.Data;

Device.StartTimer(TimeSpan.FromMilliseconds(200), () =>
{
    var firstItem = ((List<Person>)this.DataGrid.ItemsSource).First();
    this.DataGrid.SelectItem(firstItem);

    if (DataGrid.SelectedItem != null)
    {
        DisplayAlert("", " ", "cancel");
    }
    return false;
});

Regards,
Didi
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.