1

How to set a list box to a certain selected item

Let's say I have a list box (ListBox1) with 2 values (Test1 and Test2) with multi-select off. It is currently showing "Test2". I know how to know what it is set to and use that elsewhere in scripting. What I haven't figured out though is how to set that list box to another value in the script. Let's say I want a button that will set that list box mentioned above to the value of "Test1". How could I do this? I think an example of the script for that simple thing would help me with things where I might need to do something like this.

2 replies

null
    • Director of Business Solutions
    • Ken_Wyant
    • 9 mths ago
    • Reported - view

    Hey James.  Here is a quick example that I hope gets you going in the right direction.

            public void Thing1_OnClick(object sender, EventArgs eventArgs)
            {
                ListBox1.SelectedItems = new string[] {"Pick thing 1"};
            }

    public void Thing2_OnClick(object sender, EventArgs eventArgs)
            {
                ListBox1.SelectedItems = new string[] {"Pick thing 2"};
            }

      • wise_james
      • 9 mths ago
      • Reported - view

      Ken Wyant Thank you! Exactly what I was looking for and worked fine.

Content aside

print this pagePrint this page
  • Status Answered
  • 1 Likes
  • 9 mths agoLast active
  • 2Replies
  • 40Views
  • 2 Following