473,385 Members | 1,602 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,385 software developers and data experts.

Listview items

I created a listview to view 5 columns from sql database
I can search & view records using for loop but the problem is that the
object "listviewitem1" is the same so whatever record i select i get the
same first record and ignore all other records..
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});
}

}
Nov 16 '05 #1
1 1794
On Mon, 15 Nov 2004 04:28:23 +0200, "Islam Elkhayat"
<is******@yahoo.com> wrote:
I created a listview to view 5 columns from sql database
I can search & view records using for loop but the problem is that the
object "listviewitem1" is the same so whatever record i select i get the


Hello,

I don't have plenty of time so I took a short look to your for-loop. I
checked it with a small csv-File and it works. You do not have to use
AddRange this works pretty well too:

listView1.Items.Add(listViewItem1);

So it seems that your problem is somewhere in the database query. :(
Nov 16 '05 #2

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...
12
by: Dennis | last post by:
I have a form which has a ListView control named ListView1 added at design time. When I add items using the following code, they don't appear in the list view. However, if I create a ListView...
6
by: Nick | last post by:
Hi there, I'm trying to implement drag-drop for my listview control in large icon view mode. Unfortunately the order of the items gets completely messed up upon inserting the item back into the...
12
by: J L | last post by:
When I fill a listview, I resize the columns to fit the data. I need to know if the data will fit vertically or if there will be a vertical scroll bar. I need to know this so I can allow for it on...
1
by: Chris | last post by:
Hi all, I posted the following in microsoft.public.dotnet.framework.windowsforms but it seems that group has little traffic. Hi all, I have a listview box which is populated from methods of...
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: samoore33 | last post by:
I found this code on MSDN, and it works great. It creates a ListView dynamically and add items to it and all. It is great. I have changed a few of the column names to suit me. Dim listView1 As...
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...
1
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, In my application I need to periodically remove all current items from a ListView and add a new set into it. The following abbreviated code contains the basic idea: private void...
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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.