简体   繁体   English

C#TableLayoutPanel-第二行内容未显示

[英]C# TableLayoutPanel - 2nd row content not displayed

I have a user control that displays an object. 我有一个显示对象的用户控件。 This user control is composed of : 该用户控件包括:

- A main TableLayoutPanel with 2 rows to separate things in two parts
    - A nested TableLayoutPanel containing a "header"
        - A label for the name of the object
        - Several buttons...
    - A second nested TableLayoutPanel containing the members of the object
        - Dynamically added user controls...

All these controls, rows and columns are in AutoSize mode. 所有这些控件,行和列均处于“自动调整大小”模式。

This user control that represents an object is initialized based on a JSON file. 表示对象的此用户控件是根据JSON文件初始化的。 The children (ie properties of the JSON object) are added dynamically into the second nested TableLayoutPanel. 子级(即JSON对象的属性)被动态添加到第二个嵌套的TableLayoutPanel中。

I'm not going to provide the whole code because it would be too long to read, but children are added this way : 我不会提供完整的代码,因为它读起来太长了,但是以这种方式添加了子代:

propertiesTableLayoutPanel.Controls.Add(memberView, 0, propertiesTableLayoutPanel.RowCount - 1);
++propertiesTableLayoutPanel.RowCount;

Basically I always keep an empty row. 基本上,我总是保持空白行。 When adding a child, I put it into this empty row and then create another empty row by incrementing the row count. 添加孩子时,我将其放入此空行,然后通过增加行数来创建另一个空行。 I do this in order to copy the style of the row when I add a new one, though I'm not sure this is actually needed. 我这样做是为了在添加新行时复制行的样式,尽管我不确定是否确实需要这样做。

My problem is that, for some unknown reason, the 2nd child user control (index = 1) is never displayed. 我的问题是,由于某些未知原因,第二子用户控件(索引= 1)从不显示。 And it's always the second one. 而且它始终是第二个。 The row is displayed, but it seems to be empty. 该行已显示,但似乎为空。 The first one (index = 0) and the following ones (index > 2) are displayed properly. 正确显示第一个(索引= 0)和随后的一个(索引> 2)。

I have made sure by debugging and logging that all the children user controls are properly placed within the second nested TableLayoutPanel, and that their Visible property is set to true , but it doesn't seem to be enough. 我已经通过调试和记录确保所有子用户控件都正确放置在第二个嵌套的TableLayoutPanel中,并且它们的Visible属性设置为true ,但这似乎还不够。

Am I missing something about styles or anything ? 我是否缺少有关样式的内容? Thank you. 谢谢。

EDIT : Might have to do something with the RowStyles, and probably the row height. 编辑 :可能必须对RowStyles以及行高度进行某些操作。 Seems like there are already two row styles when I only have one row, which is strange. 当我只有一行时,似乎已经有两种行样式,这很奇怪。

EDIT : Seems like row height is not used when using AutoSize mode anyway. 编辑 :似乎在使用自动调整大小模式时不使用行高。

Fix here : stackoverflow.com/questions/37808238/ Was due to garbage left by the designer. 在这里修复:stackoverflow.com/questions/37808238/是由于设计者留下的垃圾。 An extra RowStyle that shouldn't have been there and that can safely be removed manually. 额外的RowStyle不应该在那里,并且可以安全地手动删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM