I have this to show all records from database to listview
private void populatelistview()
{
listView1.Items.Clear();
using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand SqlCommand = new SqlCommand("Select * from Employee", myDatabaseConnection))
{
SqlCommand.CommandType = CommandType.Text;
SqlDataReader dr = SqlCommand.ExecuteReader();
while (dr.Read())
{
listView1.Items.Add(new ListViewItem(new string[] { dr["EmpID"].ToString(), dr["Lname"].ToString(), dr["Fname"].ToString() }));
}
}
}
}
For example I have this result:
EmpID | Lname | Fname
40001 | Smith | John
40002 | Jones | David
40003 | Bryan | Kobe
How I will programmatically select an item from the list above? For example I type 40002 in the textBox then this will be selected 40002 | Jones | David
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…