38748

Add padding to last ListView item in WinForms

Question:

How can I add some extra space between the last item in a listview and the bottom of the control? I don't want to add an empty item to the bottom of the list.

Answer1:

You can't do this directly. Unfortunately the styling options of ListView are rather limited.

Unless you go for owner-drawing it.. Which is powerful and not very hard. But even there I doubt that the Items can have different Heights..

But there is a simple trick you can use:

Remove the LV's borders and place it inside a Panel with appropriate borders. Dock it there to Fill the Panel and give the Panel a Padding of maybe (0;0;0,10) and voila, the will always be a Padding of 10 pixels that looks as if it belongs to the ListView..

Instead of using the Designer, you could put these lines in the Form.Load to make it work on startup:

Panel P = new Panel(); P.BackColor = listView1.BackColor; P.Location = listView1.Location; P.Size = listView1.Size; P.Padding = new System.Windows.Forms.Padding(0,0,0,10); P.BorderStyle = listView1.BorderStyle; listView1.BorderStyle = BorderStyle.None; listView1.Parent = P; listView1.Dock = DockStyle.Fill; this.Controls.Add(P);

Recommend

  • How to create a Scrollable Table in Google Chrome
  • iOS 8.3 breaks automatic cell height
  • Find location of line on screen
  • How to multi update of a nested array in MondoDB?
  • What should I use to create a Windows GUI?
  • Getting the model ID from a Django form after having saved it
  • How to build a AST for a proprietary language?
  • Delphi XE3, ugly StringGrid's borders
  • Editing border of one side in a cell without CSS, only with HTML/XHTML?
  • Eclipse GUI building [duplicate]
  • media player does not work in my code
  • How to remove just the index name and not the content in Pandas multiindex data frame
  • Gnuplot multiplot: Convenient method for creating more complex layouts
  • Updating the composer.phar on Symfony2
  • CSS transition glitch
  • PXAction seemingly does nothing
  • Grails eager fetch doesn't retrieve all data
  • Whats the best way of persisting data to Isolated Storage on Windows Phone 7?
  • How to extract a number from a string [duplicate]
  • Google Calendar Api is not showing event list
  • How to get a list with description of all dba packages
  • Zeromq with python hangs if connecting to invalid socket
  • How to access meteor package name inside package?
  • how do i write assembly code from c#?
  • How to get latest version of a artifact on Bintray using JSONP
  • Tell Git to stop prompting me for conflicts when none really exist?
  • Android Activity.onWindowFocusChanged doesn't get called from within TabHost
  • Zoom in and out of jPanel
  • Graphics.CopyFromScreen [Web application] + The handle is invalid
  • ListItem.Attributes.Add not working
  • Excel's Macro-Recorder usage
  • Debug.DrawLine not showing in the GameView
  • How to use carriage return with multiple line?
  • Android fill_parent issue
  • Weird JavaScript statement, what does it mean?
  • php design question - will a Helper help here?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • need help with bizarre java.net.HttpURLConnection behavior
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How do I use LINQ to get all the Items that have a particular SubItem?