Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by iddkfa · May 05, 2017 at 01:23 PM · dropdowninteractableoption

Make Dropdown option non-interactable

Hi everybody!

I ran into a problem for what i didn't found a solution or maybe i was researching in the wrong direction entirely.

I have 2 Dropdowns, each populated with a String-List. I want to look if the selected option of DropdownA also exists in DopdownB and make it non-interactable. I just can't figure out how to access variables of a specific/single option.

At this point, i feel like pretty much anything would help. Thanks in advance.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class dropdowntest : MonoBehaviour
 {
     List<string> listA = new List<string>() { "select option", "---", "option1", "option2", "---", "option3", "option4" };
     List<string> listB = new List<string>() { "select option", "---", "option1", "option2", "---", "option3", "option4", "option5", "option6" };
     public Dropdown dropdownA, dropdownB;
 
 
     void Start()
     {
         PopulateLists();
     }
 
     void PopulateLists()
     {
         dropdownA.AddOptions(listA);
         dropdownB.AddOptions(listB);
     }
 
     // get text of selected dropdownA option and make DropdownB option with the same string non-interactable
     public void non_interactable()
     {
         {
             // make DropdownB option interactable = false
         }
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Davirtuoso · May 06, 2017 at 04:51 PM

I actually have done something similar in my most recent project, though not quite the same. For me, I was selecting something from my first dropdown, and then removing it from the list in my second dropdown completely so it couldn't be selected. In my case, both lists were replicas of eachother so, index 3 of list one was the same as index 3 of list two. I'm not sure if this would actually be an option for you or not, but essentially to do this you could create a method that runs when dropdown A is changed (something you can set up in unity):

 public void UpdateListB()
 {
     int toRemove = DropdownA.GetComponent<Dropdown> ().value;
     DropdownB.GetComponent<Dropdown> ().ClearOptions ();
     List DropBList = new List<string> (listB);
     DropBList.RemoveAt(toRemove);
     DropdownB.GetComponent<Dropdown>().AddOptions(DropBList);
 }

That would essentially find the index of the item in Dropdown A, clear Dropdown B, create a temporary list containing all of the items from listB, remove the item at the same index in Dropdown B then finally populate Dropdown B with all of the remaining items of your temporary list.

It worked like a charm for what I needed, I hope it helps you too. Good luck!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image iddkfa · May 08, 2017 at 01:08 AM 0
Share

Hi and thanks for answering.

Doing it this way is absolutely an option and it's what i'd done initially. I guess my main idea is more about a cosmetic/visual appeal. The additional benefit of making an option non-interactable would be the "---"-string could act as a separator.

avatar image Davirtuoso iddkfa · May 08, 2017 at 11:40 PM 0
Share

Ahhh! That makes more sense now! Well I've not used it myself, but I'm aware of an attribute you can use in dropdowns which would disable a specified index from being selectable in a dropdown list:

 DropdownA.items[0].Attributes.Add("disabled","disabled");

I believe that line would get index 0 of DropdownA (which would be 'select option' from the look of things) and disable the ability to interact with it. Hopefully from that you'll be able to adapt that line to do whatever it is you'd like to do for your lists, but the only thing you'd need to change is the DropdownA at the start and the index you want disable if you'd like to use it elsewhere. I hope that works for you :-)

avatar image
0

Answer by Jviaches · Jan 22, 2019 at 11:42 PM

for me making non iteractable first options was :

     languageDropDwn = GameObject.Find("lang-dropdown").GetComponent<Dropdown>();
     languageDropDwn.interactable = false;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Drop down list to inspector 2 Answers

Make use of a button in a drop down menu? 0 Answers

When accessing the Add Component drop-down menu, the following display issue occurs. How can I resolve this? 0 Answers

Getting information of which Dropdown menu has been changed 0 Answers

Block until Dropdown value has changed? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges