I have a class that generates a listview dynamically and placed it in a tab control. When the user resizes the form, I want to capture that event and resize the listview. I can set the dock property but directly on top of the grid there is a panel with a combo box ( allows user to sort of filter the data). And when I set the docking the grid docks to the top of the tab and doesn’t realize there is a combo there. Maybe i am doing something wrong.
Here is a sample code:
public class KI_Tab_Items_ListviewControl : KI_Tab_Items, IDisposable
{
private ListView m_Listview = new ListView();
private ComboBox m_ComboBox = new ComboBox();
public ListView ListViewControl { get { return m_Listview; } set { m_Listview = value; } }
public ComboBox ComboBoxControl { get { return m_ComboBox; } set { m_ComboBox = value; } }
public override void ClearItems()
{
ListViewControl.Items.Clear();
}
public override void PopulateControls()
{
base.PopulateControls();
}
public virtual void AddColumnHeaders()
{
ListViewControl.Columns.Clear();
}
public KI_Tab_Items_ListviewControl(TabControl m_TabControl, int lIndex, bool DisplayComboBox = true)
{
if (m_TabControl.TabPages[lIndex].Controls.Count == 0)
{
int ListviewTop = 0;
m_TabControl.TabPages[lIndex].Controls.Clear();
if (DisplayComboBox)
{
m_TabControl.TabPages[lIndex].Controls.Add(ComboBoxControl);
ComboBoxControl.Dock = DockStyle.Top;
ComboBoxControl.Visible = true;
ComboBoxControl.Left = 0;
ComboBoxControl.Top = 0;
ListviewTop = ComboBoxControl.Top + ComboBoxControl.Height;
}
m_TabControl.TabPages[lIndex].Controls.Add(ListViewControl);
ListViewControl.Anchor = AnchorStyles.Top;
ListViewControl.Dock = DockStyle.Bottom;
ListViewControl.Visible = true;
ListViewControl.Top = ListviewTop;
ListViewControl.Height = m_TabControl.TabPages[lIndex].Height - ListviewTop;
}
}
void System.IDisposable.Dispose()
{
Tab_Control.Controls.Clear();
m_Listview = null;
m_ComboBox = null;
}
}
Add ListView FIRST. Set ListViewControl.Dock = DockStyle.Fill.
Add ComboBox LAST. Sett ComboBoxControl.Dock = DockStyle.Top.