ListView Final Column Autosize creates scrollbar

前端 未结 8 882
闹比i
闹比i 2021-01-13 18:23

I am implementing a custom control which derives from ListView.

I would like for the final column to fill the remaining space (Quite a common task), I have gone abou

8条回答
  •  走了就别回头了
    2021-01-13 19:09

    I know this is old question, but after reading this and then finding my own answer, I thought I would share for others reading this as well.

    The fix for me (so far holding up under basic testing) was to set Docked to None and just Anchor my ListView to the top-left of the parent. Then, in the OnClientSize changed of the parent I set the size of my ListView to fill it, and then set my column width. For whatever reason, probably timing, this fixed the scrollbar issue mentioned by the original question.

        private void ContentSplit_Panel1_ClientSizeChanged(object sender, EventArgs e)
        {
            CaseFilter.Bounds = ContentSplit.Panel1.ClientRectangle;
            if(CaseFilter.Columns.Count == 1)
                CaseFilter.Columns[0].Width = CaseFilter.ClientRectangle.Width;
        }
    

    CaseFilter is my ListView and ContentSplit.Panel1 is a SplitContainer control it is inside. When I had it set to Dock=Fill, I had the scrollbar issue, with the above changes, no problems.

提交回复
热议问题