I have a textBox named "textBoxCliente" and I want it to appear suggestions when I writte in there from the .txt file. The suggestions that I want to appear from the .txt file are in the position 1 "parts[1]", each position are separated with the caracter "|".
My .txt file is this:
- 1|Rui|Lisboa|rui@hotmail.com|912345324|14/01/2000|89564352|Empresa
- 2|Henrique|Evora|henrique@hotmail.com|914445324|17/05/2001|55464352|Particular
- 3|Andre|Agueda|andre@hotmail.com|932415374|12/11/1996|23456743|Particular
- 4|Pedro|Aveiro|pedro@hotmail.com|965342163|30/03/2002|98645372|Empresa
My code is:
public partial class Vender : UserControl
{
public Vender()
{
InitializeComponent();
}
string dir = (Environment.CurrentDirectory + "/Bd/clientes.txt");
string[] sug = new string[File.ReadAllLines(Environment.CurrentDirectory +
"/Bd/clientes.txt").Count()];
private void textBoxCliente_TextChanged(object sender, EventArgs e)
{
carrSug();
for (int i = 0; i < sug.Length; i++)
{
textBoxCliente.AutoCompleteCustomSource.Add(sug[i]);
}
textBoxCliente.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
}
private void carrSug()
{
string[] lines = File.ReadLines(dir).ToArray();
int nLine = File.ReadAllLines(dir).Count();
for (int j = 0; j <= nLine - 1; j++)
{
string[] parts = lines[j].Split(new char[] { '|' });
sug[j] = parts[1];
}
}
}
What I did was using the "string[] sug" to save the values of the position 1 of each line and then use it to show the suggestions.