How to reparent a button to a different panel?

I think I kinda know the answer to my question, but I can’t seem to get it working right. Basically, I have 2 panels. One panel is a selection menu and the other panel is the usable panel. What I’m trying to do is get the buttons that are selection menu to move to the usable panel when they are clicked.

I know that this sounds easy enough, but I think the reason that I can’t get it to work is because the panels are setup with layout group components on them (not that it matters, but the selection panel has a grid layout group on it and the usable panel has a horizontal layout group on it). The button has a layout element component on it. Because of this, the buttons transform is being driven by the GridLayoutGroup and the HorizontalLayoutGroup components. Somewhere I read about layout overriding the parents when trying to re-parent because the GUI updates at the end of the frame. Can anyone help me figure this out? Here is my code that should re-parent the button when clicked. It registers the click, but the button’s parent doesn’t change.

	public void ManageButtonMovement()
{
	Debug.Log ("I'm in the ManageButtonMovement method");

	if(charSelectPanel.gameObject.activeInHierarchy)
	{
		Debug.Log ("The charSelectPanel is active!!");

		if (gameObject.transform.IsChildOf (charSelectPanel))
		{
			Debug.Log ("The button is a child of the charSelectPanel");
			if (isAvailable)
			{
				Debug.Log ("The button is available and isn't locked!!!");
				switchPanels();
			}
		}
		
		else if(gameObject.transform.IsChildOf (useBalloonPanel))
		{
			switchPanels();
		}
	}
}

void switchPanels()
{

	if(gameObject.transform.IsChildOf(charSelectPanel))
	{
		Debug.Log ("Set the parent already!");
		gameObject.transform.SetParent (useBalloonPanel, false);
		//LayoutRebuilder.MarkLayoutForRebuild((RectTransform)charSelectPanel);
	}
	else if (gameObject.transform.IsChildOf(useBalloonPanel))
	{
		gameObject.transform.SetParent (charSelectPanel.transform, false);
		gameObject.transform.SetSiblingIndex(siblingIndex);
		//LayoutRebuilder.MarkLayoutForRebuild((RectTransform)useBalloonPanel);

	}
}

The conditional statement on line 19 needed to be changed from “if” to “else if”. The code in the original post has been updated to represent a working solution.