vb.net Datagridview scrollbar won't show last column - vb.net

I'm working with Visual studio 2012 - Visual Basic.net
In my DGV I set the .AutoSizeMode for each column as follows:
with dgv_Clients
.Columns("Name").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
.Columns("Phone").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
.Columns("Email").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
.Columns("Address").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
end with
This configuration makes all cells to show the full text inside and the last column will be as big as needed to fit the blank space.
The problem comes when I resize the form shorter than the 3 columns; the horizontal scroll bar is shown but it doesn't show the last column.
If I change the "AutoSizeMode" from "Fill" to "AllCells" the scroll bar works fine but if the form is resized too long there is an ugly blank space.
Question:
How can I make the scroll bar to show the last column when the "AutoSizeMode" is set to "Fill" ??

You can set a minimum width of the fill column like this:
.Columns("Address").MinimumWidth = 100
The default value of this property is 5.

Related

How to get the real row's height in a DataGridView?

I'm using a TabControl to insert DataGridView in each tab. The first Column of the DGV is a ButtonCollumn and I'm trying to change the padding of all cell in this first column in each DGV by using the row's height (so that all the button can be the same size), but the height is different from the one showned. It works correctly for the first Tab, but not the others.
I have tried to do the change the padding at different place in my code, in case the height may somehow not be set yet, but nothing changed.
I have set the grid's RowTemplate to a minimum. This same minimum is the one that i see when i look at the height of each row of any other tab than the first. So in the end, the padding is wrong and the button oversized.
I thought it might be because of the DGV not being drawn at that moment so the size wouldn't be set yet, but the first Tab makes me believe otherwise.
Here's my code for the padding, if it can be of any help:
For each tp As TabPage In Me.TabControl1.TabPages
Dim dgv As DataGridView = tp.Controls(0)
For each row as DataGridViewRow In dgv.Rows
dim h As integer = row.Height
row.Cells(0).Style.Padding = New Padding(12,
Math.Ceiling((h -24)/2),
12,
Math.Floor((h -24)/2))
row.Cells(0).Value = h ' For debbuging purpose
Next
Next
Edit:
When I create the DGV, the AutoSizeRowsMode is set to AllCells, WrapMode to True. (If this info can help)

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.

Completely resize DataGridView in VB.NET

I am having issues resizing a DataGridView in a VB.NET application. The DataGridView is not bound to a data source, as all data is entered into it manually.
It is currently docked in a TableLayoutPanel, set to Fill, and I would expect it to automatically resize to fit its assigned cell, but it seems to have a minimum size, at which I can not shrink it any further. This is a problem because the tablet PC I am deploying to has a much smaller resolution, so the Windows must scale properly. The TableLayoutPanels are keeping everything in the correct position, but it is crucial that my grids scale as well so that the end user can see the bottom scroll bar and all the records in the table.
This problem is pretty much the same as the one mentioned here.
If you go to AlternatingRowsDefaultCellStyle in the properties window of the datagridviewer there is Padding feature that defaults to 0,0,0,0 which represents each direction. Perhaps if you reduce the padding it will autosize up instead of being limited on the upper end moving down.
Use AutoSizeMode and FillWeight properties of columns in your datagridview
'Column 1
Dim columnindex As Int32 = Me.DataGridView1.Columns.Add("One", "One")
With Me.DataGridView1.Columns(columnindex)
.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.FillWeight = 80 'This can be used as percent value for column width
End With
'Column 2
columnindex = Me.DataGridView1.Columns.Add("Two", "Two")
With Me.DataGridView1.Columns(columnindex)
.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.FillWeight = 20
End With
Me.DataGridView1.Rows.Add({"sample text", "1"})
Me.DataGridView1.Rows.Add({"another sample text", "2"})

Add second line when a column is full from text length ultraWinGrid

Is there a way to automatically add a new line or something when a column in my ultraGrid is full? Sometimes when i load some text into a column in my ultragrid it has a longer value length than the available column field, as a result some text stays hidden. So i want when this happens to show the rest of the text in another line. Is this possible in vb.net for ultrawingrid?
You could set the CellMultiLine property as in the example below. (supposing you have one band and the column with the long text is the second one)
UltraGrid1.DisplayLayout.Bands(0).Columns(1).CellMultiLine = DefaultableBoolean.True
UltraGrid1.DisplayLayout.Bands(0).Columns(1).VertScrollBar = True
UltraGrid1.DisplayLayout.Override.DefaultRowHeight = 100
The next two lines are optional, but they serve the purpose to show immediately the column with a different height and with a vertical scrollbar

Label position should fixed right and grow to left

How can I set my labels to align on the right even when they have diffrent lenghts.
I have a set of labels which are occuring next to each other and also underneath each other.
The problem now is that they always align from the left within the label row,but I need them to align on the right as they are showing sums from other rows. Just to verify I am not talking about the text align I am looking for a solution to align my labels.
Thanks in advance
Simply set the AutoSize property to False in the designer. Adjust the size to fit the column. Then set the TextAlign to one of the right-alignment ones.
You should be able to do it at runtime using the following code:
'find the current right alignment position
Dim rightAlign As Integer = Label1.Left + Label1.Width
'set the text (assumes AutoSize is set to True)
Label1.Text = value
'adjust position so the right hand point is in the same position as before
Label1.Left = rightAlign - Label1.Width
My method is even more strange. I create the labels and then when laying out the fields for the report adjust the labels for number (etc) that are to be right aligned
Note: all labels end with 'lbl'
- txtNew is the report column text box.
- get the column's left edge plus the width of the column minus the width of the label. Works! Just not my favorite way to do it.
' *** NEED TO CALC POSITION FOR RIGHT JUSTIFY OF LABEL !!!!!
If ShouldRightJustify(rs.Fields(i).Type) Then
rpt.Section(acPageHeader).Controls(rs.Fields(i).Name & "lbl").Left = _
(lblCol + txtNew.Width) _
- rpt.Section(acPageHeader).Controls(rs.Fields(i).Name & "lbl").Width
End If
If you are asking how to do this from the designer, use the Format Menu.
Select all the controls you want to align, then click the control you want the other aligned to. Do Format > Align > Rights.
If you are trying to do this at run-time you can loop through the controls you want to align and set their .X property according to their width. For example. To align a label so that it's right side is at X=200... SomeLabel.X = 200 - SomeLabel.Width.