Do not show partially visible rows in datagridview - vb.net

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.

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.

Excel Form buttons remain in same place, but TopLeftCell is different (all after parent row is unhidden)

Cutting right to the chase, I have a tab with 4 Excel Tables stacked on top of each other. Each row has its own "up" and "down" buttons in the column to the left of the table, like this:
I shrunk the buttons to fit within the same cell (rowheight of 20). This allowed me to use the cell's TopLeftCell.Row property as follows: When clicked, stuff from the button's row is copy-pasted to the row above/below. This is the basic code:
currRow = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
If InStr(Application.Caller, "Up") > 0 Then
Move_Project_Up currRow
Else
Move_Project_Down currRow
End If
When the user gets to this tab, any empty table-rows are hidden (with a Rows(rr).EntireRow.Hidden = True). The buttons Move and size with cells so they are automatically hidden). All visible buttons work as expected. However, sometimes a user wishes to move a project from the top of one table "up" to the bottom of the above table (i.e. to a currently hidden row). You can imagine wanting to move data from row 312 "up" to row 244 in the image below:
The code successfully makes the move and unhides the row. HERE'S THE PROBLEM: when the row is unhidden, the buttons are dark gray and their TopLeftCell.Row is wrong:
They are NOT disabled. When clicked, they still trigger the assigned macro. However, I can see from a Debug.Print that their TopLeftCell.Row is not necessarily the row they are actually in. In the image above, BOTH SETS OF BUTTONS have a TopLeftCell.Row of 97. That's correct for the first set, but not the second.
Any thoughts on why this might be happening? I suspect it has to do with the unhiding of the rows, and/or the fact that there's a lot happening on this tab (e.g. over 10,000 array formulas).
Thanks in advance!
As one commenter (jkpieterse) suggested, setting the .Top property of the "broken" buttons to the .Top value of a cell in the same row worked!

Inconsistent TableLayoutPanel resize behaviur

I have two TableLayout Panels, placed one above the other on a form. They each have the same number of columns (created at runtime) that line up with each other. They are not docked, both are anchored in a parent TLP.
When I resize the form, most of the time both TLPs resize together and line up exactly. If I resize several times (usually between 5 and 10), the TLPs resize out of sync and the columns no longer line up. If I resize again, the problem usually goes away.
The Layout_Dates contains no controls, it is painted instead. The Layout_Calendar is painted and may contain a number of controls, added at runtime. The CellPaint events complete without error.
The TLPs are populated with columns like this:
Layout_Calendar.ColumnStyles.Clear()
Layout_Dates.Width = Layout_Calendar.Width
Layout_Dates.ColumnStyles.Clear()
For i = 0 To MyColumnCount - 1
Layout_Calendar.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, DayPercent))
Layout_Dates.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, DayPercent))
Next
' make last column autosize
Layout_Calendar.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.AutoSize))
Layout_Dates.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.AutoSize))
Layout_Calendar.ColumnCount = Layout_Calendar.ColumnStyles.Count
Layout_Dates.ColumnCount = Layout_Dates.ColumnStyles.Count
I have two because one scrolls vertically and the other doesn't.
I have 'try catch' statements around my cellpaint events for both panels neither of which fire an exception.
I have tried checking the column widths at runtime, but these are in % and do not change.
I've put this in the form resize event:
Layout_Dates.PerformLayout()
Layout_Calendar.PerformLayout()
Does anyone know how to:
a) prevent this happening?
b) identify programmatically that this has happened at runtime?
c) deal with it when it does?

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

Items should be arrange into three columns in CheckedListBox or listview or listbox

I have used CheckedListBox control in vb.net application.
I have several items as follow, item 1, item 2, item 3........item 100.
Now, i want all these items to arrange into three columns and then appear verticle scrollbar.
But, in CheckedListBox, it appears as horizontally. i want it to appear horizontally for just three columns and then vertical scroll should enable.
Can you please suggest if possible in CheckedListBox control or any other control and if possible then how i would have to set its property to achieve this.
I don't think you can do that in a CheckedListBox....
You could create a FlowLayoutPanel, with a fixed width and add AutoScroll = True.
Then add a number of CheckBox controls to it.
You could have problems regarding column alignment and margins. If that's the case, you can set the checkbox Autosize = False and make them a little larger (in order to contain the text)
Or you can reduce the Height of the checkboxes to reduce spaces (is this what you want?)
eg. Height = 15
Use repeat direction =horizontal and repeat column =3 for checkbox list