Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Listbox next Item

Hey guys, I have started coding this part yet for Obotle for my chessy pick up line bot for omegle. But what would be the best method to go to next item in a listbox. I don't want to use foreach or for I think thinking it starts off a first item once that item is sent it go to next item in the listbox. Anyone has a good method that would work. This isn't multi thread. a single thread.
I was thinking something like this..

Code
public void ChessyLine()
        {
            int currentLine = -1;
            if (currentLine == -1)
            {
                currentLine = listBox1.SelectedIndex;
            }
            currentLine++;
            if (currentLine < listBox1.Items.Count)
            {
                //code message listBox1.Items[currentLine];
            }
            else
            {
                //end of messages
            }
        }
You can use Listbox.Items[index] for this.
Or if you're talking about only selecting, you can do Listbox.SelectedItem +=1, don't forget to check for index overflow.
Code
private string GetNextCheesyLine()
{
     int nextIndex = (lstLines.SelectedIndex == lstLines.Items.Length) ?  0 : lstLines.SelectedIndex++;
     return lstLines.Items[nextIndex].ToString();
}

I wrote that off head. Should work.
Thanks guys, Reason why I ask about my code because I have to send the message to the stranger.

So the code would look like this.

Code
public void ChessyLine()
        {
            int currentLine = -1;
            if (currentLine == -1)
            {
                currentLine = listBox1.SelectedIndex;
            }
            currentLine++;
            if (currentLine < listBox1.Items.Count)
            {
                textSend.Invoke(new MethodInvoker(() => textSend.Text = listBox1.Items[currentLine].ToString()));
                Chat("Bot: ", Color.Blue, FontStyle.Bold, false);
                Chat(textSend.Text, Color.FromArgb(124, 133, 142), FontStyle.Regular, true);
                _omegle.SendMessage(textSend.Text);
                textSend.Invoke(new MethodInvoker(() => textSend.Text = string.Empty));
            }
            else
            {
                textSend.Invoke(new MethodInvoker(() => textSend.Text = "We're at the end of chessy lines, Good bye for now"));
                Chat("Bot: ", Color.Blue, FontStyle.Bold, false);
                Chat(textSend.Text, Color.FromArgb(124, 133, 142), FontStyle.Regular, true);
                _omegle.SendMessage(textSend.Text);
                textSend.Invoke(new MethodInvoker(() => textSend.Text = string.Empty));
            }
        }

Edit, The method I posted above works great thanks guys for the help.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by Mr. Money™Jun 29, 2017 07:41 AM 17 467 Jun 29, 2017 07:41 AM
Last Post: Mr. Money™
[C#] by Natus12345Dec 13, 2015 11:06 AM 10 323 Dec 13, 2015 11:06 AM
Last Post: Natus12345
[.NET] by Mr. Money™Dec 3, 2015 01:03 PM 12 424 Dec 3, 2015 01:03 PM
Last Post: Odus