[Feature] item starts with searchstring, sort it on top (#99), version 1.0.17.10

This commit is contained in:
Markus Hofknecht 2021-04-14 23:12:14 +02:00
parent c00c02356a
commit cdb5cb56f1
3 changed files with 33 additions and 10 deletions

View file

@ -134,7 +134,7 @@ namespace SystemTrayMenu
1); 1);
// 0 = Dark mode, 1 = Light mode // 0 = Dark mode, 1 = Light mode
if (registryValueAppsUseLightTheme != null && if (registryValueAppsUseLightTheme != null &&
registryValueAppsUseLightTheme.ToString() == "0") registryValueAppsUseLightTheme.ToString() == "0")
{ {
isDarkModeActive = true; isDarkModeActive = true;

View file

@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.17.9")] [assembly: AssemblyVersion("1.0.17.10")]
[assembly: AssemblyFileVersion("1.0.17.9")] [assembly: AssemblyFileVersion("1.0.17.10")]

View file

@ -580,13 +580,36 @@ namespace SystemTrayMenu.UserInterface
string filterField = dgv.Columns[1].Name; string filterField = dgv.Columns[1].Name;
SearchTextChanging?.Invoke(); SearchTextChanging?.Invoke();
data.DefaultView.RowFilter = string.Format( string searchString = textBoxSearch.Text.Trim();
CultureInfo.InvariantCulture, string like = string.Empty;
"[{0}] LIKE '%{1}%'", string[] splittedParts = searchString.Split(" ");
filterField, if (splittedParts.Length > 1)
textBoxSearch.Text); {
foreach (string splittedPart in splittedParts)
{
string and = string.Empty;
if (!string.IsNullOrEmpty(like))
{
and = $" AND [{filterField}]";
}
if (string.IsNullOrEmpty(textBoxSearch.Text)) like += $"{and} LIKE '%{splittedPart}%'";
}
}
else
{
like = $"LIKE '%{searchString}%'";
}
try
{
data.DefaultView.RowFilter = $"[{filterField}] {like}";
}
catch (EvaluateException)
{
}
if (string.IsNullOrEmpty(searchString))
{ {
data.DefaultView.Sort = string.Empty; data.DefaultView.Sort = string.Empty;
} }
@ -597,7 +620,7 @@ namespace SystemTrayMenu.UserInterface
foreach (DataRow row in data.Rows) foreach (DataRow row in data.Rows)
{ {
if (row[1].ToString().StartsWith( if (row[1].ToString().StartsWith(
textBoxSearch.Text, searchString,
StringComparison.InvariantCultureIgnoreCase)) StringComparison.InvariantCultureIgnoreCase))
{ {
row[columnSortIndex] = 0; row[columnSortIndex] = 0;