I have a windows form with two ListViews, one on top of the other. I need a way to be able to resize the height of the top ListView and as the height of the top ListView gets bigger the height of the bottom ListView gets smaller. Without resizing the windows form itself. Any help would be greatly appreciated.
CodePudding user response:
So you can dock one element at the top in a panel , and use the fill property of dock to dock the second one in the same panel
CodePudding user response:
You can achieve the outcome you want using SplitContainer
with Orientation=Horizontal
.
Add the SplitContainer to the MainForm
and dock it.
Add ListViews and dock them.
TEST
Class for ListViewItem
// Class for ListViewItem
public class Employee
{
public static implicit operator ListViewItem(Employee employee)
{
return new ListViewItem(new[] { employee.First, employee.Last });
}
public string First { get; set; }
public string Last { get; set; }
}
Initialization
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
protected override void onl oad(EventArgs e)
{
base.OnLoad(e);
listViewTop.View = View.Details;
listViewBottom.View = View.Details;
listViewTop.Columns.Add(nameof(Employee.First), 200);
listViewTop.Columns.Add(nameof(Employee.Last), 200);
listViewBottom.Columns.Add(nameof(Employee.First), 200);
listViewBottom.Columns.Add(nameof(Employee.Last), 200);
listViewTop.Items.Add(new Employee{ First = "Tom", Last = "Cruise", });
listViewTop.Items.Add(new Employee{ First = "Tom", Last = "Holland", });
listViewBottom.Items.Add(new Employee{ First = "Tom", Last = "Hanks", });
}
}
Screenshot
Now the two ListView
objects size in coordination with each other by dragging the Splitter
.