データベースからリストビューまでのすべてのレコードを表示するためにこれがあります
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() }));
}
}
}
}
たとえば、次の結果があります。
EmpID | Lname | Fname
40001 | Smith | John
40002 | Jones | David
40003 | Bryan | Kobe
上記のリストから項目をプログラムで選択するにはどうすればよいですか? たとえば、textBox に 40002 と入力すると、これが選択されます40002 | Jones | David