in Education by
I'm working on Windows c#. Firstly, the things those can not be change as my need are following: The Size of TableLayoutPanel is fixed. The Total # of columns are fixed. Now, I want to set a fix height for all rows but as increasing the rows, if I set the RowStyle property to Percent with 100.0F then it works fine for 3 to 4 items, but after 4-5 items, the control on one row overwrites controls on another row. I have searched for this so more but i'm not able to get the proper answer. I have also tried the AutoSize, Percent, Absolute properties of RowStyle, even though it is not working. So what to do and how? How can I achieve this? Ultimately, I want to do same like as DataGridView of Windows C#. Thanks in advance.... I'm working on WinForms...the sample code is here.. int cnt = tableLayout.RowCount = myDataTable.Rows.Count; tableLayout.Size = new System.Drawing.Size(555, 200); for (int i = 1; i <= cnt; i++) { Label lblSrNo = new Label(); lblSrNo.Text = i.ToString(); TextBox txt = new TextBox(); txt.Text = ""; txt.Size = new System.Drawing.Size(69, 20); tableLayout.Controls.Add(lblSrNo, 0, i - 1); tableLayout.Controls.Add(txt, 1, i - 1); } tableLayout.RowStyles.Clear(); foreach (RowStyle rs in tableLayout.RowStyles) tableLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); The label and textboxes are working fine for 4-5 #of rows but whenever the #of row(in this case, variable cnt in for loop) increases, the rows are overwriting each other that is one control overwrite to another...I had drag-drop the TableLayoutPanel control and created just one row and 2 columns manually. So please tell me how to do it. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I'm still new to tableLayoutPanels myself, but I noticed that at the bottom of your code, you're Clearing all the rowstyles from the collection, then you're trying to iterate through them in your foreach loop. You did this: tableLayout.RowStyles.Clear(); //now you have zero rowstyles foreach (RowStyle rs in tableLayout.RowStyles) //this will never execute tableLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); Try this instead. TableLayoutRowStyleCollection styles = tableLayout.RowStyles; foreach (RowStyle style in styles){ // Set the row height to 20 pixels. style.SizeType = SizeType.Absolute; style.Height = 20; } xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Edit: I just realized that adding N rows doesn't add N rowstyles that you can iterate through. I think what's happening is that you're adding N rows, but none of them have a rowstyles. I suppose you can Clear() the rowstyles, then just add N rowstyles similar to how you're already doing.

Related questions

0 votes
    I am trying to adjust the row height based on the cell value. The operation have to run through ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    if row height is set to _____ it is hidden Plz help me honestly… Don’t copy from google Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    if row height is set to _____ it is hidden Plz help me honestly… Don’t copy from google Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    been working on some database data calling into a .php file. The php file contains an "Add" button ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have a mat-table with a component app-order-statuses on every row. the component calls the statuses ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    Want to improve this post? Provide detailed answers to this question, including citations and an explanation of ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Take from a pack of cards all the Aces, Kings, Queens and Jacks. Arrange them in a 4 × 4 square so that every ... and one card of each suit (Heart, Spade, Diamond, Club)....
asked Feb 11, 2021 in Education by JackTerrance
0 votes
    Hi I know it's a known issue about the auto height of webview in react native, and I have tried ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    My context IINM, the percentage-height assumes that he height of the parent is available when the height is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    As you can see on jsfiddle bellow, I'm using a vue component called Vue Multiselect. When the text ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I have a ViewPager below an AppBarLayout (with a Toolbar and a TabLayout). I cannot understand why the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I'm stuck with displaying a React component named "home" that take 100% of the height of my screen ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    For some reason, the clickable region for my text is much larger in height than the div and 'a' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    For some reason, the clickable region for my text is much larger in height than the div and 'a' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I want to calculate browser height without considering browser address bar and bottom navigation bar height. The ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
...