Click here to Skip to main content
Licence 
First Posted 4 Aug 2003
Views 77,553
Bookmarked 28 times

Auto-resize list view using a shortcut trick

By | 11 Sep 2003 | Article
This is a little trick to auto-resize the columns width of a listview with only one line of code

Introduction

Windows has many shortcuts, but there is one very interesting to auto-resize the columns width of any grid, CTRL and "+" of the numeric pad. To try this feature try to set focus to the list view of Explorer (for example by selecting a file) and then press the CTRL button and the "+" button of the numeric pad, you'see columns moving untill them are perfectly sized so there's no text hided by their little width. So I tought, can I use this feature into my programs ? And this is what I done.

Using the code

Now, to send keystrokes to the active application you have to use the SendKeys.Send function. The code of the CTRL character is "^", while the plus sign is equal to {+}.

SendKeys.Send ("^{+}");

Demo project

The demo project is a simple program to search any file trought the directory tree and I used these lines of code to resize the column of the listview:
if (chkResizeGrid.Checked)
{
    lstViewFile.Focus();
    SendKeys.Send ("^{+}");
}

I have to set the focus to the grid so I'm sure that the next instruction, the Send function, will be received by the listview. Sorry, but in the demo project all the text and comments are in italian.

Conclusion

This is a little trick by Francesco Natali.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Francesco Natali

Web Developer

Italy Italy

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionResize the column width with Javascript and Norefresh,What can i do? Pinmemberbluelins15:52 11 Jan '07  
GeneralCool thing PinmemberGevik Babakhani12:09 9 Oct '03  
GeneralDemo Programm can't be found PinmemberPalm Kevin23:59 4 Sep '03  
GeneralRe: Demo Programm can't be found PinmemberFrancesco Natali0:41 12 Sep '03  
GeneralRe: Demo Programm can't be found PinmemberCool Smith21:34 6 Jun '11  
GeneralWhat's wrong with... PinmemberDaniel Turini7:26 5 Aug '03  
GeneralRe: What's wrong with... PinmemberJerry Maguire16:55 5 Aug '03  
GeneralRe: What's wrong with... PinmemberNazeeh16:46 12 Sep '03  
GeneralRe: What's wrong with... PinmemberWolfgang Kleinschmit1:54 17 Sep '03  
GeneralRe: What's wrong with... PinmemberAdie_xp0:12 10 Nov '04  
GeneralRe: What's wrong with... PinmemberSynetech8:16 28 Dec '11  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 12 Sep 2003
Article Copyright 2003 by Francesco Natali
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid