IamHuM

Hi...

In my ListView code i have 10 rows & 10 columns. I want to search 1 word say "Search" in a perticular column(& all rows) & then if i have that word in that column then only i have to select that perticu;lar row or else i have to delete that row from completely ListView .

(e.g. I am searching for word "search" in column 5 & i found that word in row no. 1 , 3 , 5 , 7 then on my form i have to display only 1 , 3 , 5 , 7 rows of that ListView)

How i can do this in C#...

Thanks ,

Vinay



Re: Windows Forms General C# - ListView

Sean Hederman

Something like:

List<ListViewItem> removeItems = new List<ListViewItem>();

for (int i = 0; i < listView1.Items.Count; i++)

{

if (listView1.ItemsIdea.SubItems[columnIndex].Text.Contains(searchString))

{

removeItems.Add(listView1.ItemsIdea);

}

}

foreach (ListViewItem item in removeItems)

{

listView1.Items.Remove(item);

}






Re: Windows Forms General C# - ListView

vinay.p

Thank for the reply...

But its giving error on following lines-

if (listView1.Items.SubItems[columnIndex].Text.Contains(searchString))

'System.Windows.Forms.ListView.ListViewItemCollection' does not contain a definition for 'SubItems'

removeItems.Add(listView1.Items);

The best overloaded method match for 'System.Windows.Forms.ListView.ListViewItemCollection.Add(string)' has some invalid arguments

Can you tell me what i have to do to remove these erors...

Thanks,

Vinay





Re: Windows Forms General C# - ListView

Dav? S. A???????

First problem fix:
if (listView1.Items[indexofitem].SubItems[columnIndex].Text.Contains(searchString))


Second problem fix:
removeItems.AddRange(listView1.Items);





Re: Windows Forms General C# - ListView

vinay.p

Thanks for immediate reply...

But i modified the code slightly but still i am getting following errors on red line shown below...

The best overloaded method match for 'System.Collections.Generic.List<System.Windows.Forms.ListViewItem>.AddRange(System.Collections.Generic.IEnumerable<System.Windows.Forms.ListViewItem>)' has some invalid arguments

Argument '1': cannot convert from 'System.Windows.Forms.ListView.ListViewItemCollection' to 'System.Collections.Generic.IEnumerable<System.Windows.Forms.ListViewItem>'

List<ListViewItem> removeItems = new List<ListViewItem>();

for (int i = 0; i < listView.Items.Count; i++)

{

if (listView.ItemsIdea.SubItems[3].Text.Contains(searchText))

{

removeItems.AddRange((listView1.Items));

}

}

Thanks,

Vinay





Re: Windows Forms General C# - ListView

vinay.p

I changed this line as ...

if (listView.ItemsIdea.SubItems[3].Text.Contains(searchText))

What is the problem here... in the above red line...