473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 1813

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
5
by: Richard Bond | last post by:
I'm having a lot of trouble programatically selecting a listview item. How do you do this? These didn't work for me in the context of the sub below (that's trying to move up an Item in the...
1
by: Shane | last post by:
I have a text box select items in a listview as text is being typed into the text box. I get the select bar to move correctly in the Listview control. If the user presses the down or up key in...
4
by: Joerg Trumpfheller | last post by:
Hey folks, I have a problem with selecting an item in a listview control from outside. Listview items are binded with unique ids. I got now an id from another control and want to select the...
5
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException...
1
by: polocar | last post by:
Hi, I'm using Visual C# 2005 (part of Visual Studio 2005 Professional Edition), and I have the following problem: I populate a ListView object with several items, and at the end of this process I...
0
by: gnrgattadi | last post by:
Hi All, Im Unable to get desktop handle in vc++.net.Is there any method existed in .net that will provide desktop handle like in vc++ GetDesktopWindow(). In my Project I have to make A...
0
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.