Winui3: How to insert in the middle of GRID in C++/WinRT?

Harshithraj1871 1,706 Reputation points
2022-10-28T11:38:26.483+00:00

Hi,

I have a 5x5 GRID. Each element in the grid are textboxes, I want to insert a row of textboxes in the center of the grid in the runtime[Say I want to insert rows when the user double clicks on the row]. It would be of great help if you could help me in achieving this behavior.

I tried ,

Grid.Children().InsertAt(INDEX, Control);  

But this didn't work, it was inserted at the beginning of the Grid[at position [0,0]] overlapping the existing control.

Developer technologies | Universal Windows Platform (UWP)
Windows development | Windows App SDK
Developer technologies | C++
0 comments No comments
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2022-10-31T09:06:58.557+00:00

    The Grid layout does not automatically change the position, you need to design your own algorithm.
    For example, when (2, 2) needs to be inserted, the positions of all controls in the grid are obtained through GetColumn and GetRow methods. If it is after (2, 1) , it needs to move backwards.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2022-10-31T07:16:56.503+00:00

    Hello @Harshithraj1871
    Welcome to Microsoft Q&A!

    You can use Grid.SetRow and Grid.SetColumn to set the position of the new control.

        Grid().SetRow(Control,INDEX);  
        Grid().SetColumn(Control, INDEX);  
    

    Thank you.
    Junjie


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.