In this article, i will teach you , how to use control's child index property while docking.
If you dock controls in a form or in a container, they will appear in order of their child index. You can dynamically set child index of controls.
Scenario: I have 3 controls in my form. Datagridview, label and button. I want my datagridview to fill my form. I want my label and button to appear at bottom. I want my datagridview to fill all the empty space.
if i add the 3 controls and write the following code and run it , the form will looks as below
In the above image, button and label are on the top of the datagridview.
dataGridView1.Dock = DockStyle.Fill;
label1.Dock = DockStyle.Bottom;
button1.Dock = DockStyle.Bottom;
To avoid this, Let us set the child index.
Now the output looks as below
What differences can you find when you compare the above 2 images ?
In the first image , button and label are on the top of the grid or overlapped with the grid while in the second image they are properly aligned to the bottom of the form.
This is because we had given the child index.
Now if we make the label visible false, the datagridview will occupy the empy space as it has dockstyle property to fill as in the below screenshot.