Maged-Obied
asked on
Filtered List Box in .Net CF & Windows Mobile 5.0
i have a list box with over 300 items, and text box to filter these items on a user input, and i am using the following code:
private void textBox1_TextChanged(objec t sender, EventArgs e)
{
listBox1.DataSource = null;
string Searchtxt = textBox1.Text;
List<string> keys = kvpList
.Where(kvp => kvp.Value.ToString().Start sWith(Sear chtxt))
.Select(kvp => kvp.Value)
.ToList();
listBox1.DataSource = new BindingSource(keys, null);
}
my problem is that this code is taking long time (3-4 sec and sometimes more) to get the filtered list.
i wanna know what is the problem with this code, is it the keyvalue pair i am using or its a performance issue from the device, or maybe it is the code itself.
can any one suggest how to do this filtration with a different way that doesn't have this performance issue?
private void textBox1_TextChanged(objec
{
listBox1.DataSource = null;
string Searchtxt = textBox1.Text;
List<string> keys = kvpList
.Where(kvp => kvp.Value.ToString().Start
.Select(kvp => kvp.Value)
.ToList();
listBox1.DataSource = new BindingSource(keys, null);
}
my problem is that this code is taking long time (3-4 sec and sometimes more) to get the filtered list.
i wanna know what is the problem with this code, is it the keyvalue pair i am using or its a performance issue from the device, or maybe it is the code itself.
can any one suggest how to do this filtration with a different way that doesn't have this performance issue?
ASKER
'System.Collections.Generi c.List<Sys tem.Collec tions.Gene ric.KeyVal uePair<str ing,string >>' does not contain a definition for 'Values' and no extension method 'Values' accepting a first argument of type 'System.Collections.Generi c.List<Sys tem.Collec tions.Gene ric.KeyVal uePair<str ing,string >>' could be found (are you missing a using directive or an assembly reference?)
Ah. Remove ".Values":
List<string> keys = new List<string>(kvpList.Count);
for (int i = 0; i < kvpList.Count; i++)
{
if (kvpList[i].StartsWith(Searchtxt)) keys.Add(kvpList[i]);
}
ASKER
also this one is not working, the kvplist is showing in the list box as key and value and i need to show the value only and this was done by LINQ.
kvp.Value.ToString()
kvp.Value.ToString()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ya this one is working, but still the same performance; thanks any way for your help.
maybe its a device problem, because the original code is working fine on another device but its CE.
while debugging the delay time coming from the loop.(new code with loop instead of LINQ)
my question now how can i do this search with any other way? if there is a way.
maybe its a device problem, because the original code is working fine on another device but its CE.
while debugging the delay time coming from the loop.(new code with loop instead of LINQ)
my question now how can i do this search with any other way? if there is a way.
Open in new window