This is my code in C# with Visual Studio 2019:
private String[] getClientData(String clientName)
{
DataTable table = labelPrinterDBDataSet.Tables["clients"];
DataRow[] datatable = table.Select("name = '" + clientName + "'");
if (datatable.Length > 0)
{
DataRow row = datatable[0];
String[] data = new String[row.ItemArray.Length];
for (int i = 0; i < row.ItemArray.Length; i++)
{
data[i] = row.ItemArray[i].ToString();
}
return data;
}
else
{
return new string[0];
}
}
private void nameListBox_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = nameListBox.GetItemText(nameListBox.SelectedItem);
clientData = getClientData(textBox1.Text);
textBox1.Text = clientData[1];
textBox2.Text = clientData[2];
}
The listBox is with a bindingSource.
When I run my program, it does allow me to write to the textBox, but if I select something from the listBox, I can no longer write to the textBox.
After doing some research, it appears to be the causesValidation property but I don't know exactly why. I changed it from true to false and the problem was solved.