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

Similar Articles

[PageSpeed] 9

"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:

selectively choosing data from column
I have a problem: I have a column with 45000 data points. But I want t make a new data set by taking every 10-th value from the 45000 column How do I do that? Please help -- Message posted from http://www.ExcelForum.com Hi, assuming there is a value in every cell in the first column, th easiest way would be to copy the worksheet to a new sheet (to preserv your original database) and select the first cell that you want t preserve in the copied sheet (eg A1), then run this code which wil delete nine rows, skip one, delete nine skip one etc until it hits blank cell: Sub del_rows() Do While ...

Sizing a Pie Chart (reduce margins)
I can't figure-out how to make my Pie Chart larger - without making the entire chart larger (ie. I want to reduce the margin space around the Pie). Any suggestions? Hi, You need to increase the plot area. To select this image a box around the pie and click in the area that would be a corner. Or use the up/down arrow to cycle through the charts major elements. Cheers Andy lkoyne wrote: > I can't figure-out how to make my Pie Chart larger - without making the > entire chart larger (ie. I want to reduce the margin space around the Pie). > Any suggestions? -- Andy ...

Exchange 5.5 SP4
We have a problem with the TOTAL K and TOTAL ITEMS column in 'Microsoft Exchange Administrator' program. When selecting the "MAILSERVER -> Private Information Store -> Mailbox Resources" mailboxes with a (presumably) larger content as 4Gb are shown as a 0K mailbox but 19,000+ items are held in that mailbox. Does anyone have experienced this and has more info for me? I would like to know whether there is a patch or so (Knowledge Base has an article, KB 285788 but that does not cover my subject). Thanks. Berry "Berry" <Berry@NOMAILSERVER.TLD> wrote ...

how to set Static's size
Env: WindowsXP, VC++6.00 I make a static by code as follows, class CMyDlg: public CDialog { protected: CStatic *m_pStatic; } void CMyDlg::CreateControl() { CString csStatic = "some text"; CRect rcStatic; int cxStatic; int cyStatic; //I don't know how to set up cxStatic and cyStatic, according to csStatic here? rcStatic.SetRect(1, 1, 1+cxStatic, 1+cyStatic); m_pStatic = new CStatic; m_pStatic->Create("", WS_VISIBLE|WS_CHILD|WS_BORDER, rcStatic, this, IDC_STATIC1); SetDlgItemText(IDC_STATIC1, csStatic); } I just don't...

Adding Columns Based on Text
Hi, I'm not sure what to call what i'm doing, so please bear with me. In column A, starting from cell A7, i have various text, for example apple, orage, grape, etc. Each of these data is followed by additiona data in the next column, B. For example, apple - new, or apple - old. Column C will then have dollar figures relating to the prior data. What i want to do is add up only the columns that have apple, and giv a sum for that, then only the columns for oranges, then give a sum fo that, and so on. Is there a way to do this as opposed to manually adding each item? Sorry if I...

Columns
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) I am working on a translation. <br> I created parallel columns as per: <br><br>I am cutting and pasting my earlier work into this format. However, my footnotes are not moving over. I tried to insert footnotes in this new version, but that option was not available in the text box. <br><br>How do I get footnotes or endnotes for the text in the text boxes? You can have either text boxes or footnotes. Footnotes cannot exist in text boxes because text boxes are not part of the text, they're graphi...

drop-down menu font size
I am including a drop-down list in an Excel workbook. When the item is selected from the list it is entered into the workbook at the correct font size i.e. 20 point. However in the drop-down list it is illegible as it is only about 5 point. Does anyone know how to change the font size in the drop-down list Thanks in advance Bob If drop-down list is from Data Validation you cannot change the point size, which is 8 pts. For workarounds see Debra Dalgleish's site. http://www.contextures.on.ca/xlDataVal08.html#Font Gord Dibben Excel MVP On Wed, 28 Sep 2005 14:37:03 -0700, "Bob...

AUTO FILTER OR ADVANCED FILTER
This discussion Group has veen a great help Now that I have been able to view my duplicates for the past few months, I would like to know how I can set it up where it automatically ,in a new sheet, shows me the the data sorted by address of the current week that is a duplicate of a previous week. Ive been looking at www.contextures.com/ but I cant seem to find an example that would help me out. I think it would have something to do with the criteria I think. Thanks for your help. I also want to make sure that all the duplicate addresses are in this new sheet so then I can review them for what...

CListCtrl + key navigation
Hi, can any body please tell me how to handle key navigation in CLIst Control. I am not able to get the correct selected row on key down event. Thanks, Ritu int nSelectedRow = -1; DWORD dwPos = ::GetMessagePos(); CPoint pt((int)LOWORD (dwPos),(int)HIWORD (dwPos)); m_listDataTable.ScreenToClient(&pt); int nIndex = m_listDataTable.GetTopIndex(); int nLastIndex = nIndex + m_listDataTable.GetCountPerPage(); if (nLastIndex > m_listDataTable.GetItemCount()) nLastIndex = m_listDataTable.GetItemCount(); while (nIndex <= nLastIndex) { // Get the bounding rectangle of an ite...

Auto report from DBs in 3 different sites
Hi, I'm not sure if this is the right section to post this question, so pls bear with me. I want to find out if its possible to AUTOMATE updates to a DB report from data we receive from outside sites. I created 3 DBs used in 3 different sites, they all have the same forms, the only difference is the study ID#s. These sites send me the DB with weekly updates, I would like to automate these updates for our reports instead of importing manually, is this possible? Pls let me know THANKS! It isn't clear what you want to do with the 3 different databases or the rep...

merge columns
Greetings. I have data in Column B (same text in each field) that I want to add to all of the fields in Column A (different text in each field) I have tried merge & center and tried to work out how to do a CONCATENATE but am totally stuck. Is there any way to add the sentence in Col B to the end of the text in Col A without cutting and pasting on every line?? Tell me there is an easy way to do this!! If its a formula I need to use - where on earth do you write it?? Many thanks in advance =A1&B1 (as a formula in cell C1, for example) will do your concatenation (or =A1&&quo...

counting identical items in a column and returning the occurrences
I use excell 2000. I have one column with 700 rows. In each cell is one number, either a 0, 1, 2, 3, 4, or 5. In the second column I have five rows, each with one number in increasing order: 0, 1, 2, 3, 4, 5. Next to the numbers 0-5 (in column three) I want the total number of occurances for each number in column one. So out of the 700 rows, if the number 2 occurred 230 times, I want the number 230 to show in column 3 to correspond to the number 2 in column two. Any ideas? Try this: In C1 (to count the zeros) =COUNTIF($A$1:$A$701,"0") In C2 (to count the 1s): ...

How do I give a column a name in Excel? One would think this coul.
This should be easy to find in Excel Help but then again I guess we are talking about MS here so all bets are off. Hi do you want to change the column heading (from A.....IV to something else)?. If yes: not possible in Excel. You may use the first row as column header and then use 'Windows - Freeze Panes' to always show this first row -- Regards Frank Kabel Frankfurt, Germany astute1 wrote: > This should be easy to find in Excel Help but then again I guess we > are talking about MS here so all bets are off. Select the range/column and do insert>name>define Under ...

CListCtrl #7
Hello, I am trying to create a CListCtrl that has 4 columns in report mode. The first 3 columns need to be bitmaps and the 4th column needs to be text. I can get the first column set to a bitmap but the next two subitems will not display the bitmaps. Anyone have a solution to this problem?? Thanks in advance! ...

FTP File Size from wininet
I'm using the wininet.dll FtpGetFile and FtpPutFile functions from VBA, but they just return a boolean success-or-fail. Does anyone know how to get more info about the transfer, e.g. why it failed or how many bytes were transferred? Phil Hibbs. I've got this working now by separately querying the file size before download or after upload. Here is my FTP module, mostly cribbed from the interweb. FTP_Get_File and FTP_Put_File are my generic functions, at the end. One minor concern I have is that I'm not calling any function to close the file, but that shouldn't be a p...

automatic calculation and adjustment of MonthlyTransfer to credit
I'm currently using Money 2004 & have been using money for 10 years. I have entered all my future bills and transfers. I've also entered a monthly transfer to my Credit Card - but I find that I have to manually adjust the amount due in each of the next 12 months in order to get an accurate indication in the Forecast cash flow (FCF). I'm sure I'm like many money users, where I pay by credit card in full on the last day that it is due (ie 55 days interest free). Is there a more recent version of MS Money that will AUTOMATICALLY CALCULATE AND ADJUST THE DATES AND ...

sort column by last digit
Lets say I have a column like: 12435G 19995 188884G 188465 277745 etc etc etc ...and I want to sort it so that the ones that end with the letter G are isolated. Is there a way to do this? -- Kepf ------------------------------------------------------------------------ Kepf's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=30611 View this thread: http://www.excelforum.com/showthread.php?threadid=502969 In a helper column, add =IF(RIGHT(A1)="G","G","") then sort by the helper column. -- HTH Bob Phillips (remove nothere from...

Outlook 2002 and email auto suggest? #2
1 - How do I turn this option on/off? 2 - How do I remove any cached names that could be incorrect over time? ...

Size of Excel Spreadsheet
Hello, I have a small Excel spreadsheet that I created by taking an old fil and deleting what I don't need. Now it consists of ONE sheet, n macros, no graphs, nothing but a few cells with simple formulas. But the size of the file is more than 14 Mo !!! Any idea why this can be the case ? Many thanks, pierr -- Message posted from http://www.ExcelForum.com Hi see: http://www.contextures.com/xlfaqApp.html#Unused -- Regards Frank Kabel Frankfurt, Germany "Philippon >" <<Philippon.1bwnvy@excelforum-nospam.com> schrieb im Newsbeitrag news:Philippon.1bwnvy@excelforum-no...

Does Excel support Auto fill on filtered data?
I have to give continous numbers for a some rows after skipping some rows here and there in between. I am giving membership numbers to a club. There are old members and new members. Old members are given one sequence of numbers and new members another sequence of numbers. But all the old and new members are arranged in alpahabetical order of their names in my worksheet. So I filtered all old members first. (I have a column "member status" in which "old" or "new" is entered.) After filtering for old, how do I give the numbers continuosly using the auto fi...

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...

ClistCtrl and how to cross out a line
Hello I have CListCtrl object and style LVS_REPORT, but I can't make a horizontal line to cross out one line with subitems. So please help: How to do that line? m. >I have CListCtrl object and style LVS_REPORT, but I can't make a >horizontal line to cross out one line with subitems. >So please help: How to do that line? There's no build-in functionality to display strikeout text - but you can probably do it yourself by the custom draw facility - see NM_CUSTOMDRAW documentation in MSDN. Dave In addition to David's advice these articles may help: http://www.codeg...

how do I make columns independent of each other?
I am using Excel 2007 with survey results and would like to sort them by question. There are 6 worksheets of data: one per campus with approximately 50 questions in the survey and 40 replies per campus. It is too cumbersome to manually perform all these steps. I have the questions separated by column and the answers are numerical ratings. I would like to sort these answers by column independently without regard for the other columns. I would also like to determine the percentage of those who answered 1, 2, 3, etc. Is there any way to do this? Thanks, teacher2010 Sometimes k...

match first and last name and insert column into existing sheet
I have two sheets, Sheet1 and Sheet 2 In Sheet1 and Sheet2 Last name and first name are in column A and B (respectivly) However, Sheet2 is a pivot table. I need to insert column I and J of Sheet2 into Sheet1 if the first and last name matches exactly. I am having issues with the funtion, and do not know if I need to do something differently because it is a pivot table Use the GetPivotData function. See here: http://www.contextures.com/xlPivot06.html HTH, Ryan--- -- Ryan--- If this information was helpful, please indicate this by clicking ''Yes''....

format a column
I have a simple question to ask, I have a column in Excel is number like 142000, I want to format the whole column numbers without the two ending 0s, change 142000 to 1420, how can I do that? Thanks -- xcao ------------------------------------------------------------------------ xcao's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=14538 View this thread: http://www.excelforum.com/showthread.php?threadid=471821 Enter 100 in an empty cell and copy it. Then, select your range of numbers you want to change, Right Click and go to Paste Special, and select Div...