Datagrid, Anchor and Form Load

  • Thread starter Thread starter scorpion53061
  • Start date Start date
S

scorpion53061

I have a datagrid that I create dynamically in code and want it to
appear when a link label is clicked.

The form loads in maximized view.

When the datagrid appears though I have anchored it to right, left, top
and bottom the grid appears sized as if it were still at normal view. If
I size it down it gets even smaller.

How can I when the form loads in maximized view, tell it to anchor and
have it anchor to the edges as I asked for?
 
I have a datagrid that I create dynamically in code and want it to
appear when a link label is clicked.

The form loads in maximized view.

When the datagrid appears though I have anchored it to right, left, top
and bottom the grid appears sized as if it were still at normal view. If
I size it down it gets even smaller.

How can I when the form loads in maximized view, tell it to anchor and
have it anchor to the edges as I asked for?

Code please.

Cheers

Arne Janning
 
Kelly,

Did you maybe placed in on a panel or something it anchors to its parent.

When you want to anchor it to the edge, than is the Dock in my opinion much
nicer

Cor

"scorpion53061".
 
Create a form.

Tell the form to maximize in the property window at start.

In the form load event place:

Dim mydatagrid as New Datagrid
mydatagrid.Location = New System.Drawing.Point(264, 176)
Mydatagrid.Size = New System.Drawing.Size(700, 500)
mydatagrid.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _
' Or System.Windows.Forms.AnchorStyles.Left) _
' Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)

Mydatagrid.Visible = True

The form will only size to what you declared as size and not anchor to
the sides as it will otherwise.

Any ideas would be helpful.
 
In the form load event place:

Dim mydatagrid as New Datagrid
mydatagrid.Location = New System.Drawing.Point(264, 176)
Mydatagrid.Size = New System.Drawing.Size(700, 500)
mydatagrid.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _
' Or System.Windows.Forms.AnchorStyles.Left) _
' Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)

Mydatagrid.Visible = True
 
Kelly,

When this is your only code than that datagrid you create will never be on
screen, maybe you have as well somewhere another one.
Dim mydatagrid as New Datagrid

'Probably is this sentence above the guild and could be deleted
mydatagrid.Location = New System.Drawing.Point(264, 176)
Mydatagrid.Size = New System.Drawing.Size(700, 500)
mydatagrid.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _
' Or System.Windows.Forms.AnchorStyles.Left) _
' Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
Mydatagrid.Visible = True

Otherwise there should be something as
me.controls.add(mydatagrid)

I hope this helps?

Cor
 
You are right. You will see the size problem if you add

Me.Controls.Add(mydatagrid)
 
Kelly,

I have used this code (yours with some new measurements and the form
measurment as well)

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.Size = New System.Drawing.Size(750, 570)
Dim mydatagrid As New DataGrid
mydatagrid.Location = New System.Drawing.Point(25, 25)
mydatagrid.Size = New System.Drawing.Size(700, 500)
mydatagrid.Anchor = _
CType((((System.Windows.Forms.AnchorStyles.Top _
Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), _
System.Windows.Forms.AnchorStyles)
mydatagrid.Visible = True
Me.Controls.Add(mydatagrid)
End Sub
///

It shows me a nice form with in the middle an empty datagrid, which when I
maximize becomes larger and when I minimize becomes smaller, can you test
this as well?

I hope it helps?

Cor
 
Back
Top