Click here to Skip to main content
15,905,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone! I need some help with my listbox in an application i've done. First of all i have 2 variables, one that keeps count of how many items there are in the listbox and another that counts how many "Kills i've done in one trip" (the program is basically made for a game where i log all the drops i get from a specific boss). I have a searchfunction where i can search for any item and calculate the rate of getting the drop etc. But i have a button which resets the "Kills this trip" variable to zero aswell and I would like the searchfunction to search for only those items that i've got on that trip when i check a checkbox (Next time i add an item, the variables for "kills this trip" will increment with 1 again). Let's say i've done 100 kills in total and then reset "kills this trip" to zero, then I just want the search function to search for items after the 100th item. This is how my searchfunction code looks like:

C#
string searchString = textBox1.Text; //searchstring for the searchfunction

           if (searchString.Equals("")) //checks that the textfield isn't empty
           {
               MessageBox.Show("Enter an item!", "Obs");
           }
           else
           {

               for (int i = 0; i < droplog.Items.Count; i++)
               {
                   if (droplog.Items[i].ToString().IndexOf(searchString, StringComparison.OrdinalIgnoreCase) >= 0)
                   {
                       droplog.SetSelected(i, true);
                   }
                   else
                   {
                       // Do this if you want to select in the ListBox only the results of the latest search.
                       droplog.SetSelected(i, false);
                   }
               }
Posted
Comments
ZurdoDev 20-Mar-14 20:28pm    
Where are you stuck?

C#
if(droplog.Items["YOURPLACE"].toString()=="YOURPLACE")
{
//Your CODE
}
 
Share this answer
 
v2
Add another variable to your code which will store your search start index and set value to 0 on program start:
C#
private int searchStartIndex = 0

In your reset button code set value of searchStartIndex to actual count of ListBox.Item:
C#
searchStartIndex = dropLog.Items.Count;

Next step is to modify your for loop to start searching from specified item:
C#
for (int i = searchStartIndex; i < droplog.Items.Count; i++)


I hope you find this useful :)
 
Share this answer
 
Comments
Gramas19 21-Mar-14 9:12am    
Thank you! It didn't work exactly as i wished but your solution gave me a great hint so I could figuer it out myself how to do the rest, i added a new variable and did some calculating and now it works! Thanks for your help :)
Marcin Kozub 21-Mar-14 9:17am    
You're welcome :)
It would be nice if you accept solution.
Gramas19 21-Mar-14 9:24am    
Done that now :)
Marcin Kozub 21-Mar-14 9:24am    
Thx :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900