Im trying to do my roulette game, i already did two tetxbox (number[textbox1],bet[textbox2]) it gives me data from textboxes to listview.
But i got stuck at my action button, absolutly dont know how to seach in listview.

For example: listview1.text = number.text.. *(if number at listview will be same as number in text box which is random generated.
Is there any way how to do it?

Actually i got this:

Bet button, two textbox (textbox1 is which number you want to bet and textbox2 is how many cash)

private void button4_Click(object sender, EventArgs e)
        {
            if (Int32.Parse(textBox1.Text) <=36) // Bet number 
            {
                label4.Text = textBox1.Text; // Bet number from textbox will be trensfered to label, to see what was your bet
                MessageBox.Show("Bet is complete");
            }
            else
            {
                MessageBox.Show("Bet number must be from 0 to 36. Bet again");
            }

            if (Int32.Parse(textBox2.Text) <= Int32.Parse(CreditNr.Text))
            {
                BetNumber = Int32.Parse(textBox2.Text);
                BetNr.Text = BetNumber.ToString();
                CreditNumber = (CreditNumber - BetNumber);
                CreditNr.Text = CreditNumber.ToString();
                label5.Text = textBox2.Text; // Bet will be transfered to label, to see what was your bet
                ListViewItem item = new ListViewItem();
                item.Text = textBox1.Text;
                item.SubItems.Add(BetNumber.ToString());
                listView1.Items.Add(item);
                MessageBox.Show("Bet is complete");
            }
            else
            {
                MessageBox.Show("You dont have enought money");
            }


        }

Random generator

private int RandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max);
        }

And play button

number.text is where show the random number

 private void button2_Click(object sender, EventArgs e)
        {

            number.Text = RandomNumber(0, 36).ToString(); // v textboxu number se zobrazí číslo od 0 do 36
            MessageBox.Show("Number Is: " + number.Text); // zobrazí v messageboxu číslo které je napsáno v number

            foreach (ListViewItem item in listView1)
            {
                if (item.Text = number.Text)
                {
                    WinNumber = (BetNumber * 36);
                    WinNr.Text = WinNumber.ToString();
                    CreditNumber = (CreditNumber + WinNumber);
                    CreditNr.Text = CreditNumber.ToString();
                    label4.Text = "";
                    label5.Text = "";

                    MessageBox.Show("You won.");
                }
                else
                {
                    MessageBox.Show("You lost.");
                    label4.Text = "";
                    label5.Text = "";
                }


            }
        }

Looks like all works but at play button i dont know how to get if the number in number.text is in listview.
Also someone know how to make the count than? for example list.view.Bet = ( BetNumber*36)
Can someone tell me what i do wrong please?

If you want to search an item in a ListView, you could use this

If I am getting your problem right and as suggested by "ddanbe", I would suggest you to use CollectionViewSource if possible as it has got in built search functionality and that may ease the issues you are facing a bit :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.