-3

so I have a list where I have all my inputs, then to show them I'm using a propertyGrid. I want to have 2 buttons PREVIOUS and NEXT that I'll be using them to go through my property grid (list, actually) and its inputs. The code I used for that is this one:

private void btnStanga_Click(object sender, EventArgs e)
        {
            if (index < angajati.Count - 1)
            {
                index += 1;
                propertyGrid1.SelectedObject = angajati[index];
            }
        }

        private void btnDreapta_Click(object sender, EventArgs e)
        {
            if (index > 0)
            {
                index -= 1;
                propertyGrid1.SelectedObject = angajati[index];
            }
        }

But it doesn't work the way I want to, in order for the buttons to have a reaction and do what I want, I need to press each of them like 3 times in a row :( What am I doing wrong?

  • Have you tried printing the array to see what it contains, or reading the documentation for the split method? – Guy Incognito Dec 13 '20 at 21:32
  • Welcome to StackOverflow! Thank you for trusting us with this question. It seem the answer you desire can be found in [the official documentation for the line you're confused about](https://www.google.com/search?q=java+documentation+string+%22split%22) – Ky - Dec 13 '20 at 21:34
  • 2
    [Direct link](https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/String.html#split(java.lang.String)) to the most recent documentation. As Guy Incognito suggested, you can always see the contents of an array by printing it like so: `System.out.println(Arrays.toString(parts));`. This is always the best way to figure things out, just try it and see what happens. – Charlie Armstrong Dec 13 '20 at 21:39
  • Oh yes, as Charlie mentioned, "try it yourself" is also a fun and fast way to learn! – Ky - Dec 13 '20 at 21:45
  • yessss, I was panicking last night, I ended up searching and of course trying it myself AFTER I POSTED THE QUESTIONS, haha, thank you anyway for the comments<3 – ImNotSureWhatName Dec 14 '20 at 12:27

1 Answers1

0

split breaks a string to an array by a delimiter. The resulting array in this case will have two elements - "004" and "034556".

Mureinik
  • 297,002
  • 52
  • 306
  • 350