I have a list box metalListbox and 4 textboxes rtxt_num,name,docname,wiloc.
The listbox is bound to a data source with OleDb, and on
private void metal_metalListbox_SelectedIndexChanged(object sender, EventArgs e)
details from the selected value will show in the textboxes. Everything goes well except when selecting three certain values from the listbox.
- 12 Ft Accurpress Press Brake
- ETS 2000 (14 Ft Accurpress)
- First Article Inspection (Metal)
When I select one of these three, the listbox snaps to the first entry and won't let me select them, but continues working. If I click these again, it will just snap to the first entry again.
I thought it might be the file names or other details in the textboxes that it's showing. Due to the (), but 12 ft accurpress has no (). Maybe due to the numbers, but I have other entries with numbers.
No errors or anything pops up, so it almost works :(
Here's the code:
private void metal_metalListbox_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "select * from Metal where Name = '" + metalListbox.Text + "'";
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
metal_rtxt_num.Text = reader["Number"].ToString();
metal_rtxt_name.Text = reader["Name"].ToString();
metal_rtxt_docname.Text = reader["docName"].ToString();
metal_rtxt_wiloc.Text = reader["wiLoc"].ToString();
}
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
}
metalListbox.Text
is the problem (it should not!) and how the query works.. – TaW