从列表框中的特定位置搜索? [英] Search from a specific place in my listbox?

查看:79
本文介绍了从列表框中的特定位置搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!在我已完成的应用程序中,我需要对列表框提供一些帮助。首先,我有2个变量,一个用于计算列表框中有多少项目,另一个用于计算我在一次旅行中完成了多少次杀戮(该程序基本上用于我记录所有项目的游戏)我从一个特定的老板得到的滴)。我有一个搜索功能,我可以搜索任何项目并计算下降的速度等。但我有一个按钮,将杀死此行程变量重置为零,我希望搜索功能只搜索那些项目当我检查一个复选框时,我已经完成了这次旅行(下次我添加一个项目时,杀死此行程的变量将再次增加1)。假设我已经完成了100次杀戮然后将杀死此行程重置为零,那么我只想让搜索功能在第100项之后搜索项目。这是我的搜索功能代码的样子:



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:

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);
                   }
               }

推荐答案

if(droplog.Items["YOURPLACE"].toString()=="YOURPLACE")
{
//Your CODE
}


在代码中添加另一个变量,它将存储您的搜索开始索引,并在程序启动时将值设置为0:

Add another variable to your code which will store your search start index and set value to 0 on program start:
private int searchStartIndex = 0



在您的重置按钮代码中,searchStartIndex的值设置为ListBox.Item的实际数量:


In your reset button code set value of searchStartIndex to actual count of ListBox.Item:

searchStartIndex = dropLog.Items.Count;



下一步是修改 for 循环以启动se从指定项目开始拱起:


Next step is to modify your for loop to start searching from specified item:

for (int i = searchStartIndex; i < droplog.Items.Count; i++)





我希望你觉得这很有用:)



I hope you find this useful :)


这篇关于从列表框中的特定位置搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆