ClistCtrl > How to auto-adjust columns size ?

Hi all,

I have a CListCtrl in report view, two columns, hidden headerCtrl.
I populate it with some items (less than 10).

I'd like to programmatically auto-adjust the columns width according to 
their content, exactly like pressing Ctrl+'+' on a ListCtrl.

Any idea ?

Thanks,
Dansk
0
dansk1 (20)
7/11/2007 3:37:00 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
2522 Views

Similar Articles

[PageSpeed] 12

"Dansk" <dansk@laouilest.com> wrote in message 
news:e1x4VF9wHHA.276@TK2MSFTNGP06.phx.gbl...
> Hi all,
>
> I have a CListCtrl in report view, two columns, hidden headerCtrl.
> I populate it with some items (less than 10).
>
> I'd like to programmatically auto-adjust the columns width according to 
> their content, exactly like pressing Ctrl+'+' on a ListCtrl.
>

#define NUM_COLS   (2)

 // Optimally resize columns
 for (int i=0; i < NUM_COLS; i++)
  m_listctrl.SetColumnWidth (i, LVSCW_AUTOSIZE_USEHEADER);

-- David



0
dc2983 (3206)
7/11/2007 3:43:03 PM
David Ching a �crit :
> "Dansk" <dansk@laouilest.com> wrote in message 
> news:e1x4VF9wHHA.276@TK2MSFTNGP06.phx.gbl...
>> Hi all,
>>
>> I have a CListCtrl in report view, two columns, hidden headerCtrl.
>> I populate it with some items (less than 10).
>>
>> I'd like to programmatically auto-adjust the columns width according to 
>> their content, exactly like pressing Ctrl+'+' on a ListCtrl.
>>
> 
> #define NUM_COLS   (2)
> 
>  // Optimally resize columns
>  for (int i=0; i < NUM_COLS; i++)
>   m_listctrl.SetColumnWidth (i, LVSCW_AUTOSIZE_USEHEADER);
> 
> -- David

Thanks a lot (fast and efficient answer), this fits exactly my need.
0
dansk1 (20)
7/11/2007 3:56:29 PM
You can also use the LVS_EX_AUTOSIZECOLUMNS style if you are targeting
windows vista.

-- 
Sheng Jiang
Microsoft MVP in VC++
"Dansk" <dansk@laouilest.com> wrote in message
news:e1x4VF9wHHA.276@TK2MSFTNGP06.phx.gbl...
> Hi all,
>
> I have a CListCtrl in report view, two columns, hidden headerCtrl.
> I populate it with some items (less than 10).
>
> I'd like to programmatically auto-adjust the columns width according to
> their content, exactly like pressing Ctrl+'+' on a ListCtrl.
>
> Any idea ?
>
> Thanks,
> Dansk


0
sheng_jiang (305)
7/11/2007 9:32:10 PM
Greetings,

You can use code below in OnSize() of ListCtrl.
As for me, I've wrote new class which based on few types of resizing (on 
previous size, percentage, and these two ways - LVSCW_AUTOSIZE, 
LVSCW_AUTOSIZE_USEHEADER). And don't forget about SetRedraw.

   this->SetRedraw(false);
   for (int i=0;i<nColumnCount;i++)
   {
    int nPercent;
     if (dataLVEX.bResizable)
    {
     SetColumnWidth(i,LVSCW_AUTOSIZE);
     int wc1 = GetColumnWidth(i);
     SetColumnWidth(i,LVSCW_AUTOSIZE_USEHEADER);
     int wc2 = GetColumnWidth(i);
     int wc = max(wc1,wc2);
     SetColumnWidth(i,wc);
    }
    this->SetRedraw(true);
   }
   Invalidate();

"Dansk" <dansk@laouilest.com> wrote in message 
news:e1x4VF9wHHA.276@TK2MSFTNGP06.phx.gbl...
> Hi all,
>
> I have a CListCtrl in report view, two columns, hidden headerCtrl.
> I populate it with some items (less than 10).
>
> I'd like to programmatically auto-adjust the columns width according to 
> their content, exactly like pressing Ctrl+'+' on a ListCtrl.
>
> Any idea ?
>
> Thanks,
> Dansk 


0
Pavel
7/12/2007 8:39:36 AM
Reply:

Similar Artilces:

Auto configuring an LDAP Address book for a Outlook profile
We have written our own LDAP Address Book which plugs into Microsoft Outlook. We are wanting to be able to automatically configure the address book to a profile when installing our product. Does anyone know if this can be done and if so how it can be done? Or even just point me in a general direction? I have looked at the Office resource kit but the configuring profiles as part of that, seems to be more for the actual install of Outlook rather than profiles and doesn't really seem to cover actually adding services (address books) to a profile. ...

hey ya'll how do i auto sum a cell using the letter x instaed of .
hey ya'll how do i auto sum a colum using the letter x instead of using a number To count number of "x"es =COUNTIF(A1:A100,"x") Gord Dibben Excel MVP On Mon, 25 Oct 2004 14:25:04 -0700, jrod98 <jrod98@discussions.microsoft.com> wrote: >hey ya'll how do i auto sum a colum using the letter x instead of using a >number Gord answered but I couldn't resist asking what the sum of x and x is? Sinister Rod Serling music here. -- Don Guillett SalesAid Software donaldb@281.com "jrod98" <jrod98@discussions.microsoft.com> wrote in mes...

UK & US Paper Sizes
Hi there, I'm a soon-to-be graphic designer based in the UK, however, most of my clients will be in the US. Does Publisher support both US and UK paper sizes? Many thanks for your help. Simon. SimonF <SimonF@discussions.microsoft.com> was very recently heard to utter: > I'm a soon-to-be graphic designer based in the UK, however, most of my > clients will be in the US. Does Publisher support both US and UK > paper sizes? Publisher supports any paper size you can throw at it, provided it does not exceed 48" (121.92 - 48" is the exact hard-coded limit; sho...

Message size limit per domain in 2003 ?
In Exchange 5.5 I could set limits on the IMC for each domain I wanted to have a smaller than standard message size limit.. my global limit is at 25mb and there are some domains that I want to have a 10mb limit since they will not accept messages larger than 10mb anyway. So, I created a new outbound SMTP connector in 2003 but mail larger than 10mb just goes out the default (*) route, even though the direct route has a lower cost. I guess it tries the connector, the message delivery fails, so it tries another route until the message gets out.. it does get out, but I want it to bounce.....

CRM Auto completes Allotments
Hi, I first posted this query on Wednesday (SA time), but did not explain very well. I have a problem being able to enter (input / specify) the allotments for a case line. For those of you who have read it before and can't or won't help, my apologies, please don't read any further. I have reposted because of the large volume of topics over the last few days. The following (I hope) explains my issue properly for anyone who is interested in helping. The 'contract line' form has greyed out the 'Allotments Used' field, after saving the contract line the system make...

Finding values in different rows/columns
This should be simple, but I'm lost. To greatly simplify my sheets: 1 11 12 13 14 15 21 22 23 24 25 31 32 33 34 35 41 42 43 44 45 2 11 12 13 14 15 21 22 23 24 25 31 32 33 34 35 41 42 43 44 45 I want to do a VLOOKUP(1,A1:A10,1,false) and return the value in D4, or VLOOKUP(2,A1:A10,1,false) and return the value in C9. In other words, find my A cell reference and return the value in a different row/column from that. Another question: When I move a cell (cell1) to another cell (cell2) a cell (cell3) that references cell1 moves its reference from cell1 to c...

Auto Correct Formulas !?
i have a Sheet with column A with all my short codes and Column B with my Long Names in. i want it so that on another sheet i type "R1" in a cell on column E it replaces it with "Results234" Is this possible. ? i have a lot of different short names and long names on the sheet. Many Thanks:D Benn --- Message posted from http://www.ExcelForum.com/ Sure, just columns A and B in a lookup table, e.g. =VLOOKUP(A2,Sheet1!$A$1:$B$100,2,0) when you type R1 i cell A2 and let's say you put this formula in B2 it will return the adjacent cell to the right of the short name...

Size Matters!
H Can anyone tell me if it is possible to the following I have a excel document that will be sent to our contact to fill in and return. Is it possible to make the form change size depending on the resoloution of the screen it is being viewed on??? Try this Declare Function GetSystemMetrics32 Lib "user32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long Function DisplayVideoResolution() As String DisplayVideoResolution = GetSystemMetrics32(0) & " x " & GetSystemMetrics32(1) End Function Sub test() If DisplayVideoResolution = "1024 x 768"...

auto fill #3
hi, i have an excel sheet with student's grades: column A has an icreasing number, column B has the name , column C has the class, column D has the grade. I would like if it is posssible when i filter the students by class at the end of the sheet to be added two columns automatically [with macro, code?? i dont know how :-( ] the first one write if the student is 1st, 2nd, 3rd, etc in the class depending on the grade (column D) and the second column write if the grade is lower than 5 the student pass or fail! Is possible the column A when i use the filter to change in a number that is the...

Combining two columns into one- Excel 2007
I have two columns of information. The first contains the date and the second contains a number. I want to combine these two into a single column where the date is the first piece of data and the number is the second, etc. etc. I have about 15000 sets of data (date and number), so to do this manually would be out of the question. Any suggestions for a "novice" programmer? Thanks Steve Clarification What I want to do is insert a blank row every other row, and then move the data in column b1 down into A2, b2 into A4 etc. Original worksheet A B 2/1/2007 45 2/2/2007 49 2/3/2007...

Print BitMap and maintain same size
I use the dcPrint.BitBlt to print a bitmap. Is there a easy way to keep the image the same size no matter what resolution the printer is at? Thanks Ronald, You might want to check StretchBlt used together with GetDeviceCaps (to get the resolution of the output device). Johan Rosengren Abstrakt Mekanik AB "Ronald" <ronald@denverresearch.com> a �crit dans le message de news:7a191f3c.0312031056.472b261d@posting.google.com... > I use the dcPrint.BitBlt to print a bitmap. > > Is there a easy way to keep the image the same size no matter what > resolution the printe...

Problem printing to a custom size paper?
I need to print onto an 8 x8 paper. I added the paper size to the printer properties - but the size does not show up when I select paper size in the print option of the document. Does anyone else have this problem? After setting the paper size in the Printer Setup, set the size in the Page Setup, Special Size. -- Don Vancouver USA "Laurvil" <Laurvil@discussions.microsoft.com> wrote in message news:81ED7207-489B-48A9-AA43-FDD5FA65E944@microsoft.com... >I need to print onto an 8 x8 paper. I added the paper size to the printer > properties - but the size does not ...

Hiding columns and custom views problem
Hello: I have defined 6 views in modules that define views. The views are simply hiding or showing columns based on a value in a hidden row. These columns are also grouped in outlines. I am having issues with one of the views which is spitting out the "can't move objects off sheet" error. I already have code in the workbook that autosets the "size with cells" property of inserted comments. Are there some caveats with hiding/showing columns which are grouped? Are there limits to the number of columns that can be manipulated in this way? My sheet has 150 colum...

auto open .xla file
hi all, i've downloaded and used rowliner by cpearson and find it very useful. is there a way to autostart it whenever i open an excel file? tnx! -- rp Hi RP, In Excel, Tools | Add-Ins | Check the Rowlier Add-in | OK If the add-in is not listed, use the browse button to navigate to it. --- Regards, Norman "rp" <rufinojr54@hotpop.com> wrote in message news:u85Drds9EHA.3504@TK2MSFTNGP12.phx.gbl... > hi all, > > i've downloaded and used rowliner by cpearson and find it very useful. is > there a way to autostart it whenever i open an excel file? &...

HOW DO I Auto inserting date and time?
Can someone out there please help me! Am trying to find what the formula would be to automatically insert date and time (in seperate columns) when another field has been filled. Ie, if cell C3 has data in it, then for C1 to automatically insert the date, and C2 to automatically insert a time. I am told that this IS possible, but I can't work out how to do it! Thank you in advance for any assistance! Shane --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.515 / Virus Database: 313 - Release Date: 01/09/2003 thank you...

Won't Auto download messages even though...
My Outlook Won't Auto download messages even though I have the settings for the POP service to check every 3 minutes. I don't get an error and when I hit Send/Receive the messages then download. Any suggestions? Rick On Wed, 3 Nov 2004 08:56:02 -0800, "Rick" <Rick@discussions.microsoft.com> wrote: >My Outlook Won't Auto download messages even though I have the settings for >the POP service to check every 3 minutes. I don't get an error and when I >hit Send/Receive the messages then download. Any suggestions? > Try increasing your polling t...

email auto reply
Is there any way to set up an automatic "out of the office" reply to incoming email in Outlook? I have looked all over and can't seem to come up with an answer. Thanks The Out of Office Assistant is only available if you are connected to an Exchange server. If you're not, you can spoof the OOA using the Rules Wizard, but Outlook must be kept running in order for the rule to work. Look here for more information: http://www.slipstick.com/rules/autoreply.htm -- Jocelyn Fiorello MVP - Outlook *** Replies sent to my e-mail address will probably not be answered -- please r...

How to stop auto restart after update?
I have Windows set up to do automatic updates. Sometimes I will find that the computer has restarted itself, and is sitting there waiting for my password. I don't want this auto restart to occur. I don't see an option just for that. Do I need to disable auto update to prevent this? GC Chips wrote: > I have Windows set up to do automatic updates. > > Sometimes I will find that the computer has restarted itself, and > is sitting there waiting for my password. > > I don't want this auto restart to occur. I don't see an option just >...

How do I print 4 postcards landscape on letter size paper
I now have Windows Vista and can't figure out how to get four postcards to appear and print on a landscape letter setup. Used to be a piece of cake - apparently solution is hidden now. All the cards alike? Do you mean Publisher 2007? Use the Avery US Letter Postcard setup. 3263 works just fine. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "George 604" <George 604@discussions.microsoft.com> wrote in message news:927A6D81-7D6B-4669-8371-E73909592644@microsoft.com... >I now have Windows Vista and can't...

auto refresh presentation
In PP 2007, I have put a powerpoint presentation on a server. User views these slides by connecting to the server. Slides are set to loop continually until Esc . Everything works fine. But if the presentaion is replaced by a new one, user still see the old slides presentation even the old .ppt file has been deleted in the server. Is there a way to refresh slides show when a new file is created? ...

How to Auto Generate and Unique ID
Hi, i would like to auto generate an unique ID for a field, how can i do auto generate,please tell me some simplest way to do, this ID is for our reference not a security issue,please help me to auto generate the ID, the ID may be in numbers or alphanumberic what ever it may be, Thangam I used this recently for an Account Auto-ID. It will go in the Form's OnLoad Event: //Adds an Auto-Gen Acct Num //Declare some variables var aNumber var bNumber var strNumber var myDate var strDate var nText var fText alert(crmForm.FormType) if(crmForm.FormType == 1) { aNumber = Math.random(); alert(...

Transfer information from column
Excel 2007 I have a large spreadsheet that was exported from a accounting file. There are four columns with addresses, (add 1, add 2...), I would like to be able to take this information and move it into one column without re-doing all the information. If I can do this, I will be able to wrap the text to fit on the same page. Sub put4columnsinto1() dim i as integer dim dlr as long dim lr as long For i = 2 To 4 dlr = Cells(Rows.Count, 1).End(xlUp).Row + 1 lr = Cells(Rows.Count, i).End(xlUp).Row Cells(1, i).Resize(lr).Copy Cells(dlr, 1) Next i End Sub -- Don Guille...

Auto Parts
Did any one or any company adapt MS RMS to the auto parts? Auto parts retailers have specific needs. Each part is usually linked to a specific car model: Make, Model, year ...etc. And they need to lookup based on the above criteria. All I could find is that it is possible to implement RMS to autoparts but no one has done it. Way to complacated. there are a few big guys that do it and RMS can't compeate. One reason is that they are also hooked up to suppliers and parts are ordered that way also they can check to see if they have stock. More work then you want. Also some parts work...

Last entry in column
I've googled this forum, but can't find what I'm looking for. Probably just not using the right terms. I want to show in a cell what the last cell in a column with data in it is. I have a worksheet with a column in which I occasionally add another entry for a VLOOKUP. I want to automatically have the range for the VLOOKUP updated when I add another item to the VLOOKUP list. So is there a way, other than VBA code, to get the last cell address for my INDIRECT VLOOKUP to use? Thanks in advance! I believe a Dynamic Range Name is what you need. It automatically expands/contracts to a...

Auto Sort ??
I have a worksheet named "Daytona" with range B2:e33. All data in the range is taken from other sheets. Row heading are B2-Name C2-Driver D2-Points E2-Total Data for column D is entered on sheet "Drivers". Data for column E is a sum taken from sheet "Results" I would like to sort the range B3:E33, decending, by column E, whenever the data in column E changes This is one sheet of 36 that have different names, but take data from the same sheet that I would like to sort as well. I've tried VBA codes from others in the forum, but those don't seem to work...