I am trying to make a control that can hold a variable amount of strings and adjust it's height dynamically by programmatically changing the height of this control.
So far I have tried the Checked Listbox and the ListView.
The listbox keeps showing a horizontal scrollbar, even though it has been set to false. The ListView looks more promising but it refuses to realign the items in the box:
public partial class Form1 : Form
{
string[] content =
{
"Lorem",
"ipsum",
"dolor",
"sit",
"amet",
"consectetur",
"adipiscing",
"elit" ,
"Integer" ,
"commodo" ,
};
ListView listView1 = new ListView();
public Form1()
{
InitializeComponent();
listView1.Size = new System.Drawing.Size(300, 22);
listView1.Font = new Font(FontFamily.GenericMonospace, 10);
listView1.CheckBoxes = true;
listView1.View = View.List;
listView1.Scrollable = false;
this.Controls.Add(listView1);
groupBox1.Controls.Add(listView1);
foreach (string str in content)
{
listView1.Items.Add(str.PadRight(12));
}
}
private void Form1_Load(object sender, EventArgs e)
{
listView1.Height = 100;
}
}
If I move the listView1.Height = 100;
to the constructor of the class it will work so obviously that's where the problem lies. I can't seem to find what the root cause of this problem is though... Should I call some member function of the listbox to re-place it's items?
Update After fiddling some more it seems that the behavior can be reproduced also by adding items to the list using the designer, setting all the anchors, snap to the edges of the form and resizing the form at runtime. Then, again, the items will not realign. Still stuck on how to force to re-position the items in the listview though.