From fc21b6a8b040167a7d86cd5353a42fd5256ae5d3 Mon Sep 17 00:00:00 2001 From: Zoe Fenris Date: Sun, 23 Jun 2024 13:49:48 +0200 Subject: [PATCH] implement characterlist-search-function --- .../MainTabs/Controls/CharacterListControl.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/OwnChar.App.Desktop/UI/MainTabs/Controls/CharacterListControl.cs b/OwnChar.App.Desktop/UI/MainTabs/Controls/CharacterListControl.cs index 4c59954..4f49cc4 100644 --- a/OwnChar.App.Desktop/UI/MainTabs/Controls/CharacterListControl.cs +++ b/OwnChar.App.Desktop/UI/MainTabs/Controls/CharacterListControl.cs @@ -143,6 +143,41 @@ public partial class CharacterListControl : UserControl mainApi.OpenTab(new TabCharView(mainApi, character), string.IsNullOrWhiteSpace(character.Name) ? CharListControlLangRes.UnnamedChar : character.Name); } + private void SearchInList() + { + var filterText = radTextBoxControl_SearchBox.Text.Trim(); + + radListView_CharList.BeginUpdate(); + + foreach (ListViewDataItem item in radListView_CharList.Items) + { + if (item.Value is Character character) + { + var isValidResult = false; + + if (!string.IsNullOrWhiteSpace(filterText)) + { + var allValues = new string[] + { + character.Name!, + character.Fandom ?? "", + character.Owner!.Name!, + }; + + foreach (var value in allValues) + { + if (!isValidResult && value.Contains(filterText)) + isValidResult = true; + } + } + + item.Visible = isValidResult; + } + } + + radListView_CharList.EndUpdate(); + } + // E V E N T S private void RadMenuItem_AddChar_Click(object sender, System.EventArgs e) @@ -162,6 +197,6 @@ public partial class CharacterListControl : UserControl private void RadTextBoxControl_SearchBox_TextChanged(object sender, System.EventArgs e) { - + SearchInList(); } }