Я хочу сделать элемент поиска в ListBox1 через TextBox4.Пример в этом видео - время перемотки 7.20 https://www.youtube.com/watch?v=7J-D4OzfX7Y; Но у меня нет базы данных.У меня есть класс для хранения данных.И я не знаю, как выполнить поиск, чтобы найти нужный мне предмет.Файл - http://dropmefiles.com/bVrnX, Foreach - Error, could not convert char type to string
, Класс , Form1See , Form2 . Не могли бы вы написать код на TextBox4, если это не затруднитвы.Я неправильно написал код TextBox4, поэтому, пожалуйста, исправьте его
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
if (Properties.Settings.Default.Accounts == null)
Properties.Settings.Default.Accounts = new List<Account>();
if (Properties.Settings.Default.Accounts != null)
{
foreach (var account in Properties.Settings.Default.Accounts)
{
listBox1.Items.Add(account);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
new Form2(listBox1).Show();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
if (Properties.Settings.Default.Accounts != null)
{
foreach (var account in Properties.Settings.Default.Accounts)
{
var registrationsList = account.Name;
listBox1.BeginUpdate();
listBox1.Items.Clear();
if (!string.IsNullOrEmpty(textBox4.Text))
{
foreach (string str in registrationsList)
{
if (str.Contains(textBox4.Text))
{
listBox1.Items.Add(str);
}
}
}
else
listBox1.Items.Add(account); //there is no any filter string, so add all data we have in Store
listBox1.EndUpdate();
}
}
}
}