ListBox.Items.Contains

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
lstRight contains the following item "Bart " and
myTempDataRow["M_Name"].ToString() returns "Bart "
with more spaces, so the

lstRight.Items.Contains(myTempDataRow["M_Name"].ToString()); is returning
false; so how can I fix this space problem?


Thanks
 
Hi,

where the listbox items come from?

if the case you presented is always teh case then you could try
myTempDataRow["M_Name"].ToString().LastIndexOf( lstRight.Items[
XXX].ToString() );


cheers,
 
Its not working!!
It comes form from a DataRow in a Dataset where:
myTempDataRow["M_Name"].ToString() represent the field M_Name as string with
the size 80 characters that's why it looks like "Bart "
and if I use myTempDataRow["M_Name"].ToString().Trim() it will not match the
Item "Bart " in the ltsRight and the
lstRight.Items.Contains(myTempDataRow["M_Name"].ToString().Trim()); will
return false again because of the space difference!!!?

Thanks
--
Regads,
Rochdi


Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

where the listbox items come from?

if the case you presented is always teh case then you could try
myTempDataRow["M_Name"].ToString().LastIndexOf( lstRight.Items[
XXX].ToString() );


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Mike said:
Hi
lstRight contains the following item "Bart " and
myTempDataRow["M_Name"].ToString() returns "Bart "
with more spaces, so the

lstRight.Items.Contains(myTempDataRow["M_Name"].ToString()); is returning
false; so how can I fix this space problem?


Thanks
 
Hi Mike,

It would work IF what you get in the listview is contained in the dataset's
row, see that I inverted what is part of what from your code.

if this do not work ( IT SHOULD ) you could always use Trim() in both sides.


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Mike said:
Its not working!!
It comes form from a DataRow in a Dataset where:
myTempDataRow["M_Name"].ToString() represent the field M_Name as string
with
the size 80 characters that's why it looks like "Bart
"
and if I use myTempDataRow["M_Name"].ToString().Trim() it will not match
the
Item "Bart " in the ltsRight and the
lstRight.Items.Contains(myTempDataRow["M_Name"].ToString().Trim()); will
return false again because of the space difference!!!?

Thanks
--
Regads,
Rochdi


Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

where the listbox items come from?

if the case you presented is always teh case then you could try
myTempDataRow["M_Name"].ToString().LastIndexOf( lstRight.Items[
XXX].ToString() );


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Mike said:
Hi
lstRight contains the following item "Bart " and
myTempDataRow["M_Name"].ToString() returns "Bart
"
with more spaces, so the

lstRight.Items.Contains(myTempDataRow["M_Name"].ToString()); is
returning
false; so how can I fix this space problem?


Thanks
 
Back
Top