Click here to Skip to main content
15,922,325 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
This question has been asked and answered, probably many times over. I create dynamic controls that make one single row in a panel each time I hit a button. When I create enough rows to make the scroll bar appear it creates a gap in my rows after scrolling down. Below is my code for one of the controls that I add to the form. Any suggestions on what to add or change in this piece?. I understand that I will probably have to add the update to each control.

C#
#region Dynamically Added Controls
    private void addChkItem(string pnType)
      {
        int leftOffset = 7;
        int topOffset = 6;

        if (pnType == "Add-On") // Bundle Panel
          {
            // Create textbox for Qty
            CheckBox chkAddItem = new CheckBox();
            // Position textbox on screen
            chkAddItem.Left = leftOffset;
            chkAddItem.Top = topOffset + AddOnRows * VERTICAL_OFFSET;
            // Set the size of the textbox
            chkAddItem.Width = 15;
            chkAddItem.Height = 14;
            // Name the new control
            chkAddItem.Name = "chkAddItem" + AddOnRows;
            //txtQtyBundle.Text = txtQtyBundle.Name;
            // Mark control for deletion
            chkAddItem.Tag = "Dispose";
            chkAddItem.Enabled = true;
            pnAddOn.Controls.Add(chkAddItem);
            }
        }


What I have tried:

I have tried certain solutions to this problem but the code being adjusted is different than what I am using. I am not experienced enough to solve this issue.
Posted
Updated 7-Feb-16 14:17pm
v2
Comments
Sergey Alexandrovich Kryukov 7-Feb-16 19:54pm    
What is Panel? CheckBox? Button? Do you think these names define the classes. No. Full type names, please.
—SA
Member 12103627 7-Feb-16 20:14pm    
Lol..a PANEL is a PANEL. I cant educate you on what a user form PANEL is currently. As my description says at the top. I dynamically create controls and when I press a button it inserts these controls in a row in the panel. Hey nevermind, just read my description again at the top. Oh and by the way, they are controls, text boxes, combos, checkboxes just in case this helps you?,,No, I dont think you are here to help. Only to make things harder for others. Keep movin' big helper ;)
Dave Kreskowiak 7-Feb-16 20:19pm    
A Panel may be a Panel but they are not the same between UI platforms. Is this a Windows Forms app, a WPF app, ASP.NET, ... what? That's what Sergey is asking. Remember, we can't seer your screen or read your mind so you have to say exactly which Panel it is.

Sergey Alexandrovich Kryukov 7-Feb-16 20:46pm    
Simply tell us the full type name of a panel. If you cannot, you are not qualified to ask this question. Just tell us the full name, that's all.
—SA
BillWoodruff 7-Feb-16 23:52pm    
"This question has been asked and answered, probably many times over." Then, how is it you haven't already found the answer ?

This type of arrogant response to someone who's trying to help you not only stops me from responding, but will stop other people here from wanting to help you. You want us to have patience with you, how about you demonstrate patience with us.

You talk about 'TextBoxes, but your code shows the use of 'CheckBoxes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900