Layout change color

1 Answer 30 Views
LayoutControl
hans
Top achievements
Rank 1
Iron
hans asked on 21 Nov 2024, 11:47 AM | edited on 29 Nov 2024, 12:33 PM
The problem is that the data is not stored in Items


using Telerik.WinControls.UI;

namespace NovaPostOrderManager.Helpers;

public class CustomAutoCompleteSuggestHelperUpdate : AutoCompleteSuggestHelper
{
    private readonly Func<string, Task<IEnumerable<DescriptionTextListDataItem>>> _fetchDataAsync;
    private CancellationTokenSource _cts = new();

    public CustomAutoCompleteSuggestHelperUpdate(RadDropDownListElement owner, Func<string, Task<IEnumerable<DescriptionTextListDataItem>>> fetchDataAsync)
        : base(owner)
    {
        _fetchDataAsync = fetchDataAsync;
    }

    protected override async void SyncItemsCore()
    {
        // Текущий текст из поля ввода
        string currentInput = Filter;

        // Проверяем, нужно ли загружать данные
        if (string.IsNullOrWhiteSpace(currentInput) || currentInput.Length < 3)
        {
            DropDownList.ListElement.Items.Clear();
            DropDownList.ClosePopup();
            return;
        }

        // Отменяем предыдущий запрос
        _cts.Cancel();
        _cts = new CancellationTokenSource();

        try
        {
            // Задержка перед началом запроса
            await Task.Delay(300, _cts.Token);

            // Загружаем данные
            var items = await _fetchDataAsync(currentInput);

            _cts.Token.ThrowIfCancellationRequested();

            DropDownList.ListElement.BeginUpdate();
            DropDownList.ListElement.Items.Clear();

            // Добавляем элементы в выпадающий список
            foreach (var item in items)
            {
                DropDownList.ListElement.Items.Add(item);
            }

            DropDownList.ListElement.EndUpdate();

            if (DropDownList.ListElement.Items.Count > 0)
            {
                DropDownList.ShowPopup(); // Показываем список, если есть элементы
            }
            else
            {
                DropDownList.ClosePopup();
            }
        }
        catch (TaskCanceledException)
        {
            // Запрос был отменён — игнорируем
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Ошибка загрузки данных: {ex.Message}");
        }
    }

    protected override bool DefaultFilter(RadListDataItem item)
    {
        if (item is not DescriptionTextListDataItem descriptionItem)
            return base.DefaultFilter(item);

        return descriptionItem.Text.Contains(Filter, StringComparison.CurrentCultureIgnoreCase) ||
               descriptionItem.DescriptionText.Contains(Filter, StringComparison.CurrentCultureIgnoreCase);
    }
}

1 Answer, 1 is accepted

Sort by
-1
Nadya | Tech Support Engineer
Telerik team
answered on 21 Nov 2024, 01:04 PM

Hello, Hans, 

Thank you for the provided picture. However, referring to a picture it is difficult to guess what is the exact setup of RadLayoutControl that you have.

Note, that RadLayoutControl has many different item types in its structure. See the following article: Items - WinForms LayoutControl - Telerik UI for WinForms

I need to know the specific types you use for advice on which one to modify. Is it possible to provide a sample project with your RadLayoutControl and its items the way you use them so that I can inspect the setup further and provide further assistance. 

You can take a look at the Customizing Appearance article that provides examples how to access different elements and customize them. RadControlSpy tool might be quite useful if you need to inspect the inner elements of our controls and change their appearance. 

Please let me know if you need further assistance.

Regards,
Nadya | Tech Support Engineer
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.

Tags
LayoutControl
Asked by
hans
Top achievements
Rank 1
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or