Page 1 of 1

Grid view in C++

Posted: 14 Apr 2021, 12:12
by BartekW
Can someone explain how to add UserControl to grid in C++?

I have some code:
contentGrid = FindName<Noesis::Grid>("TestGrid");

	UserControl* userControl = new TabControlMenu();
	contentGrid->AddVisualChild(userControl);
And it throw error: Elements is protected by method AddVisualChild.
I made something like this in c# in the past, but dont remember exactly how.
How to do this? I want to generate content in grid.

Re: Grid view in C++

Posted: 14 Apr 2021, 12:50
by jsantos
Being Grid a Panel, you need to use its Children Property:
Ptr<UserControl> userControl = MakePtr<TabControlMenu>();
grid->GetChildren()->Add(userControl);
And in case you need to set row and column:
Grid::SetColumn(userControl, x);
Grid::SetRow(userControl, y);
Please, note that the way you were creating your control is not correct and will leak memory. Make sure to read our C++ Architecture Guide.

Re: Grid view in C++

Posted: 14 Apr 2021, 13:37
by BartekW
Being Grid a Panel, you need to use its Children Property:
Ptr<UserControl> userControl = MakePtr<TabControlMenu>();
grid->GetChildren()->Add(userControl);
And in case you need to set row and column:
Grid::SetColumn(userControl, x);
Grid::SetRow(userControl, y);
Please, note that the way you were creating your control is not correct and will leak memory. Make sure to read our C++ Architecture Guide.
Thanks for reply, I have the compiler error, it throws: Pointer to uncomplited type is not allowed.
It throws on my grid pointer.
My grid pointer is Grid* type

Re: Grid view in C++

Posted: 14 Apr 2021, 13:53
by BartekW
Ok I needed include UIElementCollection header :)

Re: Grid view in C++

Posted: 14 Apr 2021, 14:02
by jsantos
Yes, make sure you are including the corresponding headers or just use the PCH header that includes everything.