Can I have toggle buttons in a selection grid?

I am trying to create a group of buttons where the user is able to have up to x buttons toggled at the same time. Is is possible to use selection grid to do this or must I create some custom code.

My idea for a custom solution would be to take in string array and then create new toggle button within foreach loop. Then somehow keep track of which buttons are toggled and have threshold for how many buttons can be toggled at the same time.

It is not an option to hard-code the buttons in because I will use this solution in many places with different string array each time.

Does anyone have experience with similar problem and is it possible to solve it in easier way than I described?

I did my custom solution for this. I used toggled buttons and had a function to check if the button could be toggled or not.

    //This function is called after click on a toggled button. If the toggled limit was reached then it will be untoggled.
    //However if the limit has not been reached then the counter is increased and the button remains toggled.
	//And at last if the button changed to untoggled then the counter is decreased.
	void checkToggleLimit(int position, int maximumAllowed, ref int counter, ref bool[] previous, ref bool[] current){
		if (previous [position]) {
			previous [position] = false;
		if (!previous [position] && counter < maximumAllowed) {
			previous [position] = true;
		if (!previous [position] && counter == maximumAllowed) {
			current[position] = false;


Then I created boolean array for buttonStates and for previous buttonStates. The arrays were initalized to false. I also had counter for number of toggles and maximum number of toggles. Here is example of where the GUI is drawn and where I call the function after the toggleState of a button changes.

for(int i = 0; i < stringArray.Length; i++){
	toggledButtons <em>= GUI.Toggle(new Rect(75 + 170*(i%4),80 + 30*(i/4), 150, 25), toggledButtons_, stringArray*, "button");*_</em>

if(toggledButtons != previousToggledButtons*){*
* checkToggleLimit(i, maximumAllowedToggles,ref numberOfToggles,ref previousToggledButtons, ref toggledButtons);*
* } *
I was placing the buttons in a grid with 4 buttons in each row.