How can I make all panels resize equally when form is maximized - vb.net

Currently when I maximize my form it resizes as it looks below.
This is due to the anchoring element stretching the two bottom panels on the left as well as causing a gap on the right since nothing is anchored right. I could fill the gap on the right by anchoring the right most panel however that would just cause it to be wider than all the other panels.
What I want is an equal resizing of the panels when the form is maximized as depicted below
How can this be achieved?

Use TableLayoutPanel:
Add TableLayoutPanel to the form and set Dock = Fill
Add 2 rows to the TableLayoutPanel (by default there is already two)
Row 1 - Height = 50%
Row 2 - Height = 50%
Add 4 columns to the TableLayoutPanel (by default there is already two)
Column 1 - Width = 25%
Column 2 - Width = 25%
Column 3 - Width = 25%
Column 4 - Width = 25%
Four panels on the left side put inside every cell of first and second columns and set Dock = Fill
Two panels on the left side put in the third and forth columns of the first row, set RowSpan = 2 and Dock = Fill

Related

How to dock panels to fill the entire form

I'm using vb.net 2017. I want to put some panels and dock them in order to create a configuration like in the attached image:
So these panels must be docked and occupies the entire form.
I've tried several docking mode , also I used the Send to back / Bring to to front but I can't do like I want.
How can I do it?
This is what I do, add a TableLayoutPanel to the form and set Dock to Fill.
Then I would add some rows and columns to it so I could combine them to produce the results. Based on what I see it looks like you should end up with 5 columns of 20% and 4 rows of 25%.
Then drag a Panel to the top left cell of the TableLayoutPanel.
Set its:
.Column = 0
.ColumnSpan = 2
.Row = 0
.RowSpan = 3
.Dock = Fill
Follow this procedure and add two more panels. One will start at row 0, column 2 and the other at row 3 column 0.
You might need to play around with the numbers to achieve the desired results. When you get what you want you can set the margins of all of the panels to 0.
I use background colors on all the panels so I can see what it looks like while setting this up.

Do not show partially visible rows in datagridview

I try to implement the following in winform vb net project (I see this work in an app written in delphi).
I wish to hide or set visibility to false of the bottom row that partially visible in dgv that is docked to fill.
I tried to implement something like this:
DataGridView1.Rows(DataGridView1.DisplayedRowCount(true) - 1).Visible = False
I think it should be called during DataBindingComplete and Resize/scroll events, but it doesn't work.
Do you have any ideas / solutions?
So what I use on one of my datagridviews is:
Dim ind As Integer = 0
ind = DataGridView1.Rows.Count - 1
DataGridView1.Rows(ind).Visible = False
which hides the last displayed row of the datagridview.
You requirement sounds somewhat odd. Your comment ”I wish to hide or set visibility to false of the bottom row that partially visible in dgv that is docked to fill.”... I am curious how you would know this is the last row? Is it not possible that there are more rows below the last one visible? If the scroll bars are available you should see the vertical one if rows go beyond its bounding box. If one of the rows is cut in half by the bounding box and there is more than 1 row below this row, then making invisible/hiding/deleting that row will simply move the next one up.
Since the DataGridView is docked you may have to resize the rows manually if you do not want the rows to be split by the bounding box. Another possible solution is to use the DataGridViews AutoSizeRowsMode Like below.
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
This will set the rows so that a row will not be chopped if it is outside the bottom of the bounding box. The rows will auto size to fit evenly There are seven (7) AutoSizeRowsMode options and I am guessing one of them may do what you are looking for. I am guessing DisplayedCells may work for what you describe. If the grid is re-sized often, you may have to implement this row resizing. Hope this helps.

Data Grid View VB.net 2013 , How many rows and which are visible in window?

I have a datagridview control with 10 rows on my form window.
Now lets suppose the size of the datagridview in the form can only display 5 rows to user and user has to use vertical scroll bar to see the other 5 rows.
now my question is :
Is there any way to know which 5 rows are currently visible to the user according to the position of scroll bar.
Actually in my program currently i am updating the all the rows value one by one of that datagridview table continuously.
Now i want to only update the rows that are visible in the window. so how can i know what rows are visible according to scroll bar position.
Thanks in advance
The DataGridView control exposes a VerticalScrollingOffset property which can be used to determine how far the view is scrolled. If you know the height of each row in the DataGridView in pixels, you can then calculate which rows of the table are currently visible and refresh them.
The height of each row can be determined through the DataGridViewRow property Height. This defaults to the font height, plus 9 pixels - if you're using the same font size in all rows this should be consistent.
EDIT: Further digging through the documentation shows that each DataGridViewRow exposes a Displayed property that returns true when the row is visible on the user's screen. Checking that would be much easier!
MSDN on DataGridViewRow.Displayed property

Why do I have to set VerticalScroll.Value twice?

I've got a Windows form that contains a picturebox that holds images of differing size - width is always the width of the form, height is calculated to keep the aspect ratio steady.
The up & down arrows (and home, end keys) are configured to scroll the window - but I'm finding I have to make the following call twice to 'properly' scroll:
Me.VerticalScroll.Value += 100
Me.VerticalScroll.Value += 100
The first call changes the scroll position (but not the scrollbar position), then the second changes the scrollbar position.
Why is this? Am I setting the wrong option here?

How to Change Form Width Depending on Datagridview's Data

I have a form that contains a datagridview. The cells in the datagridview expand or contract depending on text width.
How can I make the parent form in which the data grid is docked also contract or expand to the cell (total of all cells) width?
Hence I want the parent form to change in the row (width) size and not in the column (height) size?
Im using vb.net
I would recommend just making it so that users can resize the program to the width that they want, and have the datagridview adjust it's width to fit the forms width. If you adjust it based on the columns, then it could cause issues where the form is bigger than the users screen. The easiest way to do this is by using the Dock and Anchor attributes.
If you really want to have the form adjust it's width to fit the columns, you would have to loop through the columns and add the width values together after it is databound. After you get the total width, you would have to set your forms width
The code would look something like this:
Dim intWidth As Integer
For Each dgvcc As DataGridViewColumn In DataGridView1.Columns
intWidth += dgvcc.Width
Next
Me.Width = intWidth