Hi Machi,
simply calling new ListViewItem(...) doesn't put the new item to
lsvTableIDMain.
You have to call lsvTableList.Items.Add(lsv); after the first line.
> May i know why the Contains Method always return false and IndexOf method
> always return -1 although the value for "cboTableIDMain.Text.Trim())" is
[quoted text clipped - 15 lines]
>
> ===================================================
Machi - 28 Apr 2005 10:36 GMT
I do not get what you mean. Do you see the source codes properly? I
understand that new ListViewItem(...) doesn't put the new item to the
ListView control and i don't want to put the data into listview control until
i make sure the text i want to put it in the listview control is not
available in the listview control.
I want to make sure there is no duplication of same text in the listview
control.
I, for sure can use looping to check for that, but besides that, is there
any better way to do so?
Thanks.
> Hi Machi,
>
[quoted text clipped - 21 lines]
> >
> > ===================================================
Hi Machi,
You are testing if a ListViewItem reference is already inside your ListView, not the contents of the ListViewItem.
Since you create a new ListViewItem it will have a new reference and will never be found. Contains/IndexOf will therefore always fail.
Try something like this
string s = cboTableIDMain.Text.Trim();
bool found = false;
foreach(ListViewItem lvi in lsvTableList.Items)
{
if(lvi.Text == s)
{
found = true;
break;
}
}
if(!found)
lsvTableList.Items.Add(new ListViewItem(s));
> May i know why the Contains Method always return false and IndexOf method
> always return -1 although the value for "cboTableIDMain.Text.Trim())" is the
[quoted text clipped - 14 lines]
>
> ===================================================

Signature
Happy coding!
Morten Wennevik [C# MVP]
Machi - 28 Apr 2005 10:42 GMT
Morten Wennevik, thanks for the information.
> Hi Machi,
>
[quoted text clipped - 35 lines]
> >
> > ===================================================