Я пытаюсь программно изменить количество строк в TableLayoutPanel (иногда должно быть четыре, иногда пять, а редко шесть).
К сожалению, изменение количества строк не поддерживает синхронизацию коллекции RowStyles, поэтому вы не можете установить высоту вновь добавленных строк. Следующий тестовый код демонстрирует этот факт:
private void button1_Click(object sender, EventArgs e)
{
//TableLayoutPanels start with 2 rows by default.
Debug.Assert(tableLayoutPanel1.RowStyles.Count ==
tableLayoutPanel1.RowCount);
//Cannot remove rows
tableLayoutPanel1.RowCount = 1;
Debug.Assert(tableLayoutPanel1.RowStyles.Count ==
tableLayoutPanel1.RowCount);
}
Второе утверждение неверно.
private void button2_Click(object sender, EventArgs e)
{
//TableLayoutPanels start with 2 rows by default.
Debug.Assert(tableLayoutPanel1.RowStyles.Count ==
tableLayoutPanel1.RowCount);
//Cannot add rows
tableLayoutPanel1.RowCount = 6;
Debug.Assert(tableLayoutPanel1.RowStyles.Count ==
tableLayoutPanel1.RowCount);
}
Второе утверждение неверно.
Итак, каков правильный программный способ установить свойство RowCount для TableLayoutPanel?





Вы пробовали создать новый RowStyle, а затем добавить его с помощью метода tableLayoutPanel1.RowStyles.Add?
Это не работает. Предположим: начните с двух строк, а затем добавьте два стиля, у вас получится шесть строк.
Об этой проблеме было сообщено в Microsoft в 2005 году, и они признали, что это ошибка , но они были "все еще оцениваю наши варианты здесь" Microsoft решила не исправлять ее («Закрыто»).
TableLayoutPanel Rows и RowStyles не соответствуют.
Описание
When you create a tableLayoutPanel, and new rows are created (either by adding rows in the program or setting the RowCount property), new RowStyles are not added to the control. Additionally, if I add new Row Styles, the number of rows is increased, but not to the same number: if I start with two Rows and two RowStyles, set Rowcount to 4, and then add two RowStyles (in design view), the Rowcount has set to 6. It seems more intuitive for the ordinality of the RowStyles collection to match the current RowCount.
Отправленный Microsoft 24.10.2005 в 18:07
This issue has been reactivated as we begin planning for the next version of Visual Studio. Over the coming months we will reconsider feedback that was previously postponed. We welcome your comments and participation in this process.
Размещено Microsoft 27.06.2005 в 6:49
The Microsoft Sub-status is now "Reproduced"
Thanks for reporting this bug, we have been able to repro this issue and are investigating.
Thank you, Prabhu, VS2005 Product Team.
Отправленный Microsoft 27.06.2005 в 17:55
Thankyou for reporting this issue. This is a peculiarity in our runtime object model that doesn't translate well to design time. At runtime the RowCount and ColCount really mean minRowCount and minColCount in terms of autogrow, because rows/cols don't need a supporting style. At design time we try to simplify that and keep a near 1:1 correspondence between styles and rows/cols. In this case, you are seeing by design runtime behavior. We already have a bug tracking this issue and are still evaluating our options here. Thanks again for contributing to a better Whidbey.
Отправленный Microsoft 06.07.2005 в 15:43
Thankyou for reporting this issue. This is a peculiarity in our runtime object model that we have chosen to not address at design time. At runtime the RowCount and ColCount really mean minRowCount and minColCount in terms of autogrow, because rows/cols don't require a supporting style. At design time we generally try to simplify that and keep a near 1:1 correspondence between styles and rows/cols. In the case of rowSpan or colSpan on a table layot panel with autogrow you can get into a state where rows/rowcount/rowstyles are out of sync. To avoid this, simply add the columns/rows you need first, then set the controls *span property. Thanks.
Отправленный Microsoft 24.10.2005 в 18:07
This issue has been reactivated as we begin planning for the next version of Visual Studio. Over the coming months we will reconsider feedback that was previously postponed. We welcome your comments and participation in this process.
-- Visual Studio Team
Каждая страница, которую я когда-либо видел на этом сайте, заканчивается без ответа или "Ухх ... Может быть, позже"
@TheBlastOne Нет; по-прежнему "Закрыто как отложенное"