Mega Code Archive

 
Categories / Delphi / VCL
 

Adjust columns of a ListView component

Title: Adjust columns of a ListView component Question: How do you adjust the columns of a ListView component ? Answer: Even if the columns of a ListView component are adjusted well with the column editor, usually a horizontal scroll bar appears together with a vertical scroll bar if you add more and more items. To get rid of the horizontal scrollbar you can adjust the width of the columns if you subtract the width of the vertical scroll bar - which can be determined with GetSystemMetrics(SM_CXVSCROLL) - from the last column: procedure AdjustListViewColumns(ListView : tListView); begin if ListView.Items.Count = ListView.VisibleRowCount then begin ListView.Columns[1].Width:= ListView.Width-ListView.Columns[0].Width-GetSystemMetrics(SM_CXVSCROLL)-4; end else ListView.Columns[1].Width:= ListView.Width-ListView.Columns[0].Width-4; end;