Telerik RadGridView in WPF: GetRowForItem method returns null after calling SortDescriptors.Reset()

StackOverflow https://stackoverflow.com/questions/18662057

문제

The GetRowForItem method returns null after calling grid.SortDescriptors.Reset(). The following code is an example of a button click event that gets the row for a selected item:

    private void GetRowForSelectedItem_Click(object sender, RoutedEventArgs e)
    {
        this.clubsGrid.SortDescriptors.Reset();
        var r = this.clubsGrid.GetRowForItem(this.clubsGrid.SelectedItem);
        MessageBox.Show(r.ToString());
    }

The value of r is null.

도움이 되었습니까?

해결책

The reason this is occurring is the Grid.SortDescriptors.Reset() method is executing on the UI thread and hasn't finished by the time the GetRowForItem method is called. Here is a workaround that seems to work well for me. I'm calling the SortDescriptors.Reset() method, and then calling BeginInvoke (with DispatcherPriority of Input) to make the call to the GetRowForItem method.

 private void GetRowForSelectedItem_Click(object sender, RoutedEventArgs e)
    {
        this.clubsGrid.SortDescriptors.Reset();

        System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
        {
            var r = this.clubsGrid.GetRowForItem(this.clubsGrid.SelectedItem);
            MessageBox.Show(r.ToString());
        }));
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top