feat: autocompletions

This commit is contained in:
2026-03-11 14:28:43 +01:00
parent da8ce47f8b
commit a0de93f98c
13 changed files with 7054 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using System.Windows.Forms;
using CarManagerV3.Util;
namespace CarManagerV3
{
@@ -29,6 +30,39 @@ namespace CarManagerV3
{
lblID.Text = $"ID: {car.Id}";
}
SetAutoCompleteForMake();
SetAutoCompleteForModel();
SetAutoCompleteForColor();
}
private void SetAutoCompleteForMake()
{
var makes = CarCompletions.GetCarBrands();
var makeAutoComplete = new AutoCompleteStringCollection();
makeAutoComplete.AddRange(makes.ToArray());
tbxMake.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
tbxMake.AutoCompleteSource = AutoCompleteSource.CustomSource;
tbxMake.AutoCompleteCustomSource = makeAutoComplete;
}
private void SetAutoCompleteForModel()
{
var models = CarCompletions.GetCarModels(tbxMake.Text);
var modelAutoComplete = new AutoCompleteStringCollection();
modelAutoComplete.AddRange(models.ToArray());
tbxModel.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
tbxModel.AutoCompleteSource = AutoCompleteSource.CustomSource;
tbxModel.AutoCompleteCustomSource = modelAutoComplete;
}
private void SetAutoCompleteForColor()
{
var colors = CarCompletions.CommonColors;
var colorAutoComplete = new AutoCompleteStringCollection();
colorAutoComplete.AddRange(colors.ToArray());
tbxColor.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
tbxColor.AutoCompleteSource = AutoCompleteSource.CustomSource;
tbxColor.AutoCompleteCustomSource = colorAutoComplete;
}
/// <summary>
@@ -69,6 +103,7 @@ namespace CarManagerV3
() => car.Make = ValueOrFormer(tbxMake.Text, car.Make),
() => tbxMake.Text = car.Make
);
SetAutoCompleteForModel();
}
private void tbxModel_TextChanged(object sender, EventArgs e)
@@ -163,7 +198,8 @@ namespace CarManagerV3
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
// Ctrl+S to save, Esc to close, Delete to delete
if (keyData == (Keys.Control | Keys.S))
{
btnSave.PerformClick();
return true; // Indicate that the key has been handled