Completed
Last Updated: 11 Oct 2022 11:00 by ADMIN
Release LIB 2020.1.203 (02/03/2020)
Dinko
Created on: 24 Jan 2020 09:52
Category: GridView
Type: Bug Report
1
GridView: SearchStateManager property is Null on loaded if ShowSearchPanel property is not set to True

SearchStateManager property is null when trying to change any of the properties of the SearchStateManager object in the Loaded event. This behavior is observed when the ShowSearchPanel property is not set to true initially.

6 comments
ADMIN
Petar Mladenov
Posted on: 11 Oct 2022 11:00

Hi Roberto,

Using custom template shouldn't be an issue as long as you use the original template part name:

this.SearchPanel = this.GetTemplateChild("PART_SearchPanel") as GridViewSearchPanel;

Last note in the suggestions - when using custom styles - make sure they are merged as early as possible - in general case this is App.xaml file.
Anyway, glad to hear you have resolved the issue on your side.

Regards,
Petar Mladenov
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.

Roberto
Posted on: 11 Oct 2022 07:40

Hello Petar.

Thanks for the reply.

I have managed to solve it using the "DataLoaded" event and now it works for me, it is probably because I use a template to change the presentation of the search panel, although it is the same for both grids. I use no-xaml libraries.

I use this event because it comes after the OnApplyTemplate.

DataGrid.DataLoaded += OnDataGridDataLoaded;

AuxiliaryDataGrid.DataLoaded += OnDataGridDataLoaded;

private void OnDataGridDataLoaded(object sender, EventArgs e)
{
    var gridView = sender as RadGridView;
    if (gridView.SearchStateManager != null)
    {
        gridView.SearchStateManager.IsSearchWithAccentEnabled = true;
        gridView.DataLoaded -= OnDataGridDataLoaded;
    }
}

 

Thank you so much.

ADMIN
Petar Mladenov
Posted on: 10 Oct 2022 14:00

Hello Roberto,

The SearchStateManager is first created in the constructor of the GridViewSearchPanel which is part of the GridViewTemplate and in the GridView's OnApplyTemplate (when the styles are applied), manager is assigned to the SearchStateManager property of the GridView. Also there is no internal logic which will make the property null. This makes me think the issue at your side is not related to the type of objects bound to the gridview, but rather a timing difference in the styles applied to the controls / or the way it is loaded in the visual tree. Could you please share more info regarding how you load the gridview - you can share XAML code. Also you can try to simplify the load somehow -for example try to isolate your scenario with single GridView defined in XAML and ViewModel bound in XAML. We tried similar setup but we cannot reproduce the manager being null on Loaded. Also please let us know which style approach you use - no-xaml binaries or xaml ones. Thanks again for your cooperation.

Regards,
Petar Mladenov
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.

Roberto
Posted on: 10 Oct 2022 07:50

Hello Petar.

I use 2022.3.912 GridView trial release with Visual Studio 2022 and net 7. I have two GridViews, one is binding to an ObservableCollection<Entity>() (Entity is a dbset ef core) and other is binding to a ObservableCollection<dynamic>().

In the ViewModel:

For the first GridView:

private ObservableCollection<TEntity> items;

public ObservableCollection<TEntity> Items
{
    get => items;
    set => SetProperty(ref items, value);
}

For the second GridView:

private readonly object locking = new();

private ObservableCollection<dynamic> auxiliaryItems = new();

public ObservableCollection<dynamic> AuxiliaryItems
{
    get => auxiliaryItems;
    set => SetProperty(ref auxiliaryItems, value);
}

In th Window Loaded event:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Loaded">
        <i:InvokeCommandAction Command="{Binding WindowLoadedCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
    </i:EventTrigger>
</i:Interaction.Triggers>

public ICommand WindowLoadedCommand => new Prism.Commands.DelegateCommand<object>(async (o) => await OnWindowLoaded(o).ConfigureAwait(false));

private async Task OnWindowLoaded(object obj)

{

    window = obj as MainWindow();

    BindingOperations.EnableCollectionSynchronization(AuxiliaryItems, locking);

    window.DataGrid.Loaded += OnDataGridLoaded();

    window.AuxiliaryDataGrid.Loaded += OnDataGridLoaded();

}

private void OnDataGridLoaded(object sender, RoutedEventArgs e)
{
    var gridView = sender as RadGridView;
    if (gridView.SearchStateManager != null)
    {
        gridView.SearchStateManager.IsSearchWithAccentEnabled = true;
    }
}

For the first datagrid, SearchStateManager is ok but for the second grid it's null.

The first time records are loaded into the grid the searchdatasource is null, but the second time it is not.

AuxiliaryItems = new ObservableCollection<dynamic>(itemsSource);

if (window.AuxiliaryDataGrid.SearchStateManager != null)
{
    CommonWindow.AuxiliaryDataGrid.SearchStateManager.IsSearchWithAccentEnabled = true;
}

This is the way I load the records.

Sorry for my english.

Best regards.

ADMIN
Petar Mladenov
Posted on: 10 Oct 2022 06:30

Hello Roberto,

Could you please add more details regarding your scenario - have you hit a runtime exception in our code or you use an event where you need the SearchStateManager initialized to perform your application logic successfully. Please specify the event you use, is it Loaded ? Also please confirm you are using our latest official Release - R3 2022. Thank you in advance.

Regards,
Petar Mladenov
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.

Roberto
Posted on: 07 Oct 2022 10:22

Hello. Sometimes the SearchStateManager is Null even though ShowSearchPanel is true.

I bind an ObservableCollection<dynamic>() to ItemsSource and I load different objects.

When the DataGrid is first Loaded, the SearchStateManager is null, but when I reload other objects in the ObservableCollection the second time it's not.