470,591 Members | 1,401 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

Unable to select ListView items

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


Nov 16 '05 #1
0 1524

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Dave Y | last post: by
5 posts views Thread by Richard Bond | last post: by
1 post views Thread by Shane | last post: by
4 posts views Thread by Joerg Trumpfheller | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.