Hi Riya,
I came across the same challenge as you and I think I have a solution!
To be sure, let's confirm the challenge: Define the height of a gallery based on the variable heights of its lines (items).
As your lines (items) have variable heights we can't just follow @zmansuri 's suggestion: count the number of lines (items) and multiply by a standard height. That wouldn't work.
What we need to do is (1) identify the height of each row (item) individually and from that (2) define the height of the gallery. Lets go!
Imagine this gallery:
- glr_Quiz (flexible height gallery)
----- lbl_Question ( control label ) AutoHeight: true; X: 0; Y: 0;
----- lbl_Answer ( control label ) AutoHeight: true; X: 0; Y: lbl_Question.Height;
1 ) Identify the height of each line (item):
I noticed that glr_Quiz.AllItems also points to the controls that make up the gallery lines (Ex.: glr_Quiz.AllItems.lbl_Question), however, there are few properties that we have access to (Ex.: .Text) and Height, a property that We would like it so much, it's not one of them...
That's when I got around the situation as follows - I added a label to the gallery that calculates the height of the line (item) in the Text field:
----- lbl_varItemHeight ( control label ) X: 0; Y: 0; Visible: false;
And in the Text field:
lbl_Question.Height + lbl_Answer.Height
Ready! we already have the height of each row (item)!
2) Set gallery height:
- Now it's easy! In glr_Quiz.Height:
//Sum of all different row heights
Sum(Self.AllItems.lbl_varItemHeight, lbl_varItemHeight.Text)
//Sum of all padding
+((CountRows(Self.AllItems)+1)*Self.TemplatePadding)
Now we have a flexible gallery that adapts its total height according to your variable height items!!!
Hope this helps.
If it helped you, please comment.
If you have a better idea, please comment too 🙂
Obs.: Sorry for my English...