From 6a52bf59ac829eac25bfb0864418d063129b95b6 Mon Sep 17 00:00:00 2001 From: KB Bot Date: Thu, 7 Aug 2025 14:31:16 +0000 Subject: [PATCH 1/2] Added new kb article autocompletebox-restrict-user-input --- .../autocompletebox-restrict-user-input.md | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 knowledge-base/autocompletebox-restrict-user-input.md diff --git a/knowledge-base/autocompletebox-restrict-user-input.md b/knowledge-base/autocompletebox-restrict-user-input.md new file mode 100644 index 000000000..76cc04dcc --- /dev/null +++ b/knowledge-base/autocompletebox-restrict-user-input.md @@ -0,0 +1,72 @@ +--- +title: Restricting User Typing in RadAutoCompleteBox +description: Learn how to prevent users from typing in the RadAutoCompleteBox in UI for WinForms. +type: how-to +page_title: Prevent User Input in RadAutoCompleteBox in UI for WinForms +meta_title: Prevent User Input in RadAutoCompleteBox in UI for WinForms +slug: autocompletebox-restrict-user-input +tags: editors, autocompletebox,keydown, customization,respect-user-input +res_type: kb +ticketid: 1691827 +--- + +## Environment + +|Product Version|Product|Author| +|----|----|----| +|2025.2.520|RadGridView for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)| + +## Description + +In the following scenario, we will demonstrate how to prevent the end user from typing in the control. The user should interact with the control only by clicking an external button (e.g., Attach), which opens a file dialog for selecting files to attach. + +## Solution + +To disable user input in the RadAutoCompleteBox, you can override its `KeyDown` method by customizing the `RadAutoCompleteBoxElement`. Follow these steps: + +1. Create a custom class that inherits from `RadAutoCompleteBox`. +2. Override the `CreateTextBoxElement` method to return the custom `RadAutoCompleteBoxElement`. +3. Inside the custom `RadAutoCompleteBoxElement`, override the `OnKeyDown` method to suppress key presses. + +Here is the code implementation: + +````C# + +public class MyAutoCompleteBoxControl : RadAutoCompleteBox +{ + public override string ThemeClassName + { + get + { + return typeof(RadAutoCompleteBox).FullName; + } + } + protected override RadTextBoxControlElement CreateTextBoxElement() + { + return new MyAutoCompleteBoxElement(); + } +} + +public class MyAutoCompleteBoxElement : RadAutoCompleteBoxElement +{ + protected override Type ThemeEffectiveType + { + get + { + return typeof(RadAutoCompleteBoxElement); + } + } + protected override void OnKeyDown(KeyEventArgs e) + { + e.SuppressKeyPress = true; + e.Handled = true; + } +} + +```` + +Replace the standard `RadAutoCompleteBox` with the custom `MyAutoCompleteBoxControl` in your application. This will prevent users from typing in the control. + +## See Also + +- [RadAutoCompleteBox Documentation](https://docs.telerik.com/devtools/winforms/controls/editors/autocompletebox/autocompletebox) From b40f7083c4938e0ee7d8875971df474267623996 Mon Sep 17 00:00:00 2001 From: Nadya Todorova <48494959+nade7o@users.noreply.github.com> Date: Mon, 11 Aug 2025 18:06:00 +0300 Subject: [PATCH 2/2] Update autocompletebox-restrict-user-input.md --- knowledge-base/autocompletebox-restrict-user-input.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knowledge-base/autocompletebox-restrict-user-input.md b/knowledge-base/autocompletebox-restrict-user-input.md index 76cc04dcc..5b5ebdb47 100644 --- a/knowledge-base/autocompletebox-restrict-user-input.md +++ b/knowledge-base/autocompletebox-restrict-user-input.md @@ -14,7 +14,7 @@ ticketid: 1691827 |Product Version|Product|Author| |----|----|----| -|2025.2.520|RadGridView for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)| +|2025.2.520|RadAutoCompleteBox for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)| ## Description