Reputation: 341
I would like to place two DataGridViews (Auto Binding ) vertically along with their labels in Winform. So it should fit with in area and look nice.
It should display on following order: DataGridView Label1 DataGridView1 DataGridView Label2 DataGridView2
It should adjust Scroll and maximize behavior automatically. I have tried with Panels and FlowLayoutPanel but was not successful. I know how to do in WPF with relative layout, but no clue how to do in winform.
Upvotes: 1
Views: 1161
Reputation: 341
I solved the problem using TableLayoutPanel control. Created four rows:
Row1: SizeType:Absolute value:20
Row2:SizeType:AutoSize
Row3: SizeType:Absolute value:20 Row4:SizeType:AutoSize
And DatagridView1.AutoSize = true; DatagridView2.AutoSize = true;
tableLayoutPanel1.AutoScroll=true;
Now, it adjust Scroll and maximize behavior automatically as per different size of DataGridViewRows
Thanks LarsTech and TaW and others for your support !!
Upvotes: 0
Reputation: 54433
The problem seems to be mainly keeping the sizes of the two DGVs in synch.
For this you can use a SplitContainer
, which will do that automatically:
Orientation = Orientation.Horizontal
IsSplitterFixed = true
FixedPanel
to None
Anchors
to your liking, maybe to all four sidesDataGridViews
in the two SplitContainer.Panels
Dock=Fill
Now both DGVs will stay at the same size, sharing the SplitContainer
size equally, or to be precise with the original ratio.
If you want Labels
to sit above each DGV, simply put them in place but instad of Dock=Fill
choose four Anchors
for the DGVs.
If you want your Buttons
to stay under the SplitContainer
simple Anchoring
will probably do..
Note that by nesting more such SplitContainers
you can keep three or more Controls
synched with the same sizes..
Upvotes: 2