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
1931 Views

Similar Articles

[PageSpeed] 26

"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 complete
I would like the program to finish my word after I have typed the first or secord letter without having to use the down arrow, or the mouse to choose a specific vendor, or customer. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolut...

CHANGING FONT IN ROW & COLUMN
When i start excel, the font of raws on the left side with 1, 2, 3, 4... numbers & colums with A B C D... characters has a font which i don't like. I want to change it. Please guide me how to do it? The font in the working sheet is Aerial which we can change easily. Palesha You can change the normal style (which will probably affect lots of other cells). Format|Style|Style Name=Normal Modify But Styles are stored with each workbook. So you could create a workbook that has the normal style you want. Then save this workbook as a template for all new workbooks. If that's what y...

Outlook 2002 Auto Send/Receive
I'm running Outlook 2002 under Win XP Pro with all MS updates applied. All of a sudden last month, Outlook stopped automatically doing a Send/Receive every minute or so. I now have to manually do Send & Receive to get/send my email. All of the settings under email options look ok. PLEASE NOTE: I've had this operating PERFECTLY without a hitch for 5+ years with the time interval set at 1 minute (in effect continuously...). What happened? Any clues? (Please no replies from "Russ" the MVP. He just doesn't get it...) TIA----------- I've had exactly the sam...

Columns
How do you navigate from one column to another? In table columns, press Tab. In snaking columns there is no reliable way except to move the mouse. You must fill one column before text will move to another unless you insert a column break (Ctrl+Shift+Enter). -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "Jackie" <Jackie@discussions.microsoft.com> wrote in message news:16AFBA66-9D70-4FCB-9704-3CCC154863FD@microsoft.com... > How do you navigate from one column to another? > On May 18, 3:44=A0...

text in a vertical column
I am trying to get a word in a coulum without having to enter each letter with a return after. In article <FA7EDA2C-5B2C-4F96-A1E3-EA6EA2913A10@microsoft.com>, Jabiru wrote: > I am trying to get a word in a coulum without having to enter each letter > with a return after. ... in what program? ...

Auto Start Powerpoint
How can i make my powerpoint presentation Auto Start thru email? I don't believe you can. There has to be some sort of inter action between the recipient and the presentation. If you save your presentation as a PowerPoint Slide Show, and if the recipient has PowerPoint or the PowerPoint viewer on their system when they click on the presentation it will start in the slide show mode. -- Michael Koerner MS MVP - PowerPoint "Autostart" <Autostart@discussions.microsoft.com> wrote in message news:BAAAAFA6-28AF-4344-9761-6AD887A4ABC5@microsoft.com... &...

Adjusted Hire Date
In what table can I find Adjusted Hire Date? -- Jenny, GP Consultant Jenny, It is available in UPR00100(Payroll Master) Table, Field is BENADJDATE -- Thanks Janakiram M.P. MCP-GP Note: If you are a Microsoft Partner, You can also Login to Dynamics GP partner forums at http://social.microsoft.com/Forums/en-US/partnerdynamicsgp/threads "Jenny" wrote: > In what table can I find Adjusted Hire Date? > -- > Jenny, GP Consultant Thanks so much for your quick response. -- Jenny, GP Consultant "Janakiram M.P." wrote: > Jenny, > > It is available i...

Page Number Font Size
How can I increase the font size of the page numbers of my power point presentation? Thanks so much. ...

auto reply email entering queue
How can I configure an autoreply function to a queue so that sender get a message back as soon he send something to a queue? I wanted to use a workflow but it seems we cannot add workflow to queues. Any idea ? -- Christophe As far as i remember this is not possible because the Exchange-Account which is used for the queue has to be "disabled". Maybe you can configure Exchange as it would auto-forward incoming mails for your queue to another Exchange-User and try to get auto-reply work this way. Another option -which is highly unsupported- is to create a trigger on Activity-Tabl...

Selective Column deletion #2
Hi, I'm not real familiar with writing code in Excel, so my question is probably fairly simple. I'm working with Census data and before importing it into SAS I want to clean it up a bit in Excel. The problem is that the Census summary tables give me three columns of information (an upper, lower, and estimate), when I only need one (estimate). The matrices I work with a usually in the 52x2000 range, so it gets very tedious to delete them by hand. Can excel handle a 'delete if' or 'select if, then delete' type of command. something like: delete if (column(contains(uppe...

How do I turn auto-correcting bullets back on?
I accidentally asked OneNote to stop autocorrecting by replacing things like - or * with bullet points. I chose "Stop automatically autocorecting" or something like that when I last made a bullet point. I found the autocorrect screen under the Tools tab, but it didn't have anything about bullet points. I also checked How do I turn this feature back on? Tools | Options | Advanced | Apply bullets to lists automatically. -- -Ben- Ben M. Schorr, MVP Roland Schorr & Tower http://www.rolandschorr.com http://www.officeforlawyers.com/outlook.html Author: The Lawye...

Font size across platform
Hello, Why do documents when opened in Macintosh are rendered a lot smaller (visually) than when opened on a PC? For example - if an excel document is created using 12pt Times New Roman, it is perfectly legible when opened on a PC. When done under osx, it is tiny and so you have to zoom in to view it (to 125-130%). If you save any changes, then the zoom is saved. So what? I am an independent consultant and work in teams that primarily use PC and there is constant filesharing between team members. It is a real nuisance when transferring files, especially clients who sometimes reduce the font...

adding columns to an arrray
How to I load into an array values from a worksheet that are not in a contiguous range? For example a 3 column array made up of (from the same row): value in F, sum of D - G, value in S -- WinXP - Office2003 (Italian) You could loop through the rows and build your array. You could pick up each non-contiguous column and build a multi-column array in your code. You could pick up the entire range at once and then just ignore the columns you don't need. Or you could even pick up each non-contiguous column and use 3 different arrays, but loop through them in sync. Here...

Adjusting text borders
I am writing a newsletter. I wish to customize the paragraph sizes. I am using Publisher 2003. Customize how? Do you want all the text boxes the same? Are you using a template? You can delete the text boxes in a template and create your own. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Punza Okie" <Punza Okie@discussions.microsoft.com> wrote in message news:1C7E19A1-3ACB-4478-8F41-7142CFC8819A@microsoft.com... > I am writing a newsletter. I wish to customize the paragraph sizes. > I am using Publisher...

CListCtrl Header height change??
CListCtrl Header height change?? Is it possible to change the height of a CListCtrl Header.? Thanks Markus ...

Format the columns 30 - 60
Wouldn't ya know after I built all of this the stupid columns are coming out as: >120, 120, 30, 60, 90 I need for them to look this way: 30, 60, 90, 120,>120 I know i've seen a post around here about this but I just couldn't find it again. Joe PS anybody seen a good course online for advanced pivot table training. I already did the Microsoft one. Joe "Anna Wood" wrote: > I need to add values in different columns of data based on due dates. > > Categories of data include: > Current Due Date (say, 2/1/09) > Grace Days (i.e...

Lookup one column and sum another column
Hi all,, Hope someone can help me with the following problem. I would like to look up Column C for a specific value (i.e. 19) and then sum the values in Column A that relates directly to the value of 19 in Column C. Thanks in advance. If you mean SUM() values in Column A that are in the same rwo as number 19's in Column C then try: =SUMIF(C1:C9,19,A1:A9) -- HTH Sandy In Perth, the ancient capital of Scotland and the crowning place of kings sandymann2@mailinator.com Replace@mailinator.com with @tiscali.co.uk "Maddoktor" <maddoktor@clinic.com> wrote in message ...

Two-Column, Two Axes Chart
Hi Folks - I have some totals in this format: Unit Count Sum Marketing 25 300 Accounting 40 400 IT 100 1000 I'd like to make a Two-column, two-axes chart. When I change either Count or Sum series to the secondary axis, the columns become stacked. Is there a way to keep them as separate columns? Thanks. Michael http://peltiertech.com/Excel/Charts/ColumnsOnTwoAxes.html - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ ...

Problems with CListCtrl
I'm having trouble with a CListCtrl object. I'm trying to automatically set the selected items of the list from my code. I try the following statement: m_List.SetItem (pos, 0, LVIF_STATE, NULL, 0, LVIS_SELECTED, LVIS_SELECTED, 0); The SetItem function returns non-zero, which supposedly means it was successful. However, I don't see any selection showing up. I even called RedrawItem on this list item, but it didn't help either. Anyone know about this? -Eric >I'm having trouble with a CListCtrl object. I'm trying to automatically >set the selected ite...

Format a column for "True / False"?
Having come from Access I am used to creating a field (column) which can be a "yes\no" or "true\false" but which actually contains "0" or "-1" Is it possible to do this in excel, and is it possible to have a check box on the worksheet which will enter the value for me regards Roga Just use TRUE/FALSE in the column. If you pick a checkbox from the controls toolbox, and link that to a cell, that sets the cell value to TRUE/FALSE. -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "roga" <...

CTreeCtrl and CListCtrl problem
I use create a single document struct using MFC(explore style).The left of the window is CLeftView class(which inherit CTreeView).The right is CBrowserView which inherit CListView.I want to display the content of a directory in the right(CListview) when user click the item of the ctreectrl. In the LeftViw I add method "void CLeftView::OnClickItem (NMHDR* pNMHDR, LRESULT* pResult)" because I want to know which item be clicked by user. ////////////////Leftview////////////////////// CTreeCtrl& mtree=GetTreeCtrl(); HTREEITEM item=mtree.GetSelectedItem(); data=mtree.GetItemDat...

Auto Reply #15
This is a multi-part message in MIME format. ------=_NextPart_000_007B_01C48A17.897CB9B0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello All, Is there an "auto-reply" feature in Outlook 2000? Thanks! Clay ------=_NextPart_000_007B_01C48A17.897CB9B0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset...

Resize the DialogBox and adjust the controls inside.
hi all, how to size the dialog when dragged with the mouse when i run a dialogbox. adujust all the controls inside the dialog. please provide a solution. thanks, uday. "uday" <uday@discussions.microsoft.com> wrote in message news:A1A055CF-084F-446B-8B19-A8E635BFB578@microsoft.com... > hi all, > > how to size the dialog when dragged with the mouse when i run a dialogbox. > adujust all the controls inside the dialog. please provide a solution. Take a look at this: http://www.codeproject.com/dialog/resizabledialog.asp -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo...

Auto-dial with salesforce.com
Does anyone know of a plug-in utility we can use to auto-dial from salesforce.com? We do not require predictive dialing, only ability to click on a contact and dial. Thank you. ...

Exchange 5.5 Static Routes Auto import
Exchange 5.5 Static Routes Auto import Hi We are having an issue with an exchange 5.5 server running on NT . The server is auto importing routes to remote devices and putting static routes into the routing table. ipconfig shows that server adddresses are in the same subnet as the server, with default gateway of the local router. There are also addresses for other subnets via the next hop router. This happens on other servers in the same subnet, but these servers don't have the same problem as exchange. When a client connects to the server, routes are added to the server. afte...