In my Application i search my Employee database and view result in List View
with 3 column..
here is the code:
#########################################
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
this.listView1.Items.Clear();
this.button2.Enabled = true;
dataSet11.Clear();
string txtbox = textBox1.Text;
string sqlstr= "select EmployeeID, FirstName, LastName, Title from employees
where "+src +" like '"+txtbox+"%'";
SqlCommand searchfill = new SqlCommand(sqlstr,sqlConnection1);
sqlDataAdapter1.SelectCommand = searchfill;
sqlDataAdapter1.Fill(dataSet11);
int n= dataSet11.Tables["Employees"].Rows.Count;
statusBar1.Panels[0].Text = " Number of Employees Found : "+n.ToString();
for(x=0; x<n; x++)
{
string str1 = dataSet11.Employees[x].FirstName.ToString();
string str2 = dataSet11.Employees[x].LastName.ToString();
string str3 =dataSet11.Employees[x].Title.ToString();
listViewItem1= new ListViewItem(new string[] {str1,str2,str3} , -1);
//listView1.Items.AddRange(new ListViewItem[] {
// listViewItem1});
listView1.Items.Add(listViewItem1);
}
##########################################
the code work great and i can search and narrow the listview items depend on
the textbox string
but when i select any item and try to send the information to new windows to
edit the database Field i always get the first item in the list even if i
selected any items
i think this is coz ( listviewitem1) value change in the loop instead of
creating "listiewitem2... 3... 4" for each item...
how can i make this work??
thanx