Solved

Need to display large bodies of text in a List View

Posted on 2004-08-06
51
733 Views
Last Modified: 2013-11-20
Is there a way to overcome what seems to be an undocumented maximum width of about 250 chars? I'm attempting to display data that is stored in the Access Memo column type. I can retrieve the data without a problem using ODBC and the CLongBinary class (verified in the debugger). However, when I attempt to display it, the data is truncated.
0
Comment
Question by:tma050898
  • 22
  • 16
  • 11
51 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11741123
How are you trying to display, a text box?
0
 
LVL 3

Author Comment

by:tma050898
ID: 11741138
I'm using a list view window (via the MFC CListCtrl class)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11741167
You say you have read data without problem, so I assume you have verified size and is correct. Try to display your data in a message box:

::AfxMessageBox(yourDataAsStringHere);
0
 
LVL 3

Author Comment

by:tma050898
ID: 11741200
>>>...so I assume you have verified size and is correct
Correct. As I mentioned, I've verified in the debugger that the entire value is being read correctly.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11742558
Listview - I assume it is in report mode.  Which has a maximum of ONE LINE, is it that you are running up against?

You may need to redisign your app and just a normal CView based view and do the displaying in the OnPaint.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11742606
Yes, it's in report mode. I have no problem with it being on one line. However, the text is being truncated - which is the problem. I need to display the entire text value in each cell.

Basically, what I'm asking is What is the maximum length of text that can be inserted into an list view via InsertItem/SetItemText? If it's less than about 2,000 chars, then I need to know if there's a way to circumvent that limitation without resorting to owner/custom draw.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11742683
I've not seen anything in help.

Also I have just quickly butchered (on owner draw) list and displayed ca 600 char long strings in it apparently without a problem
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11742794
What kind of data do you present? Maybe some special character is truncating display. What about the MessageBox, have presented data as expected?
If you can,please post a sample of your data.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11742866
Andy,
Yep. Unfortunately, I can't find anything either. I've seen the question asked in other forums (askign how to display 2k text strings in a list view), but noone has answered it. It might just come down to me owner-drawing the string.

Jaime,
As I noted, the value is correctly returned from my database library to the demo ui. Here's the string:
0123456789_000_0123456789_001_0123456789_002_0123456789_003_0123456789_004_0123456789_005_01234567
89_006_0123456789_007_0123456789_008_0123456789_009_0123456789_010_0123456789_011_0123456789_012_0
123456789_013_0123456789_014_0123456789_015_0123456789_016_0123456789_017_0123456789_018_0123456789
_019_0123456789_020_0123456789_021_0123456789_022_0123456789_023_0123456789_024_0123456789_025_0123
456789_026_0123456789_027_0123456789_028_0123456789_029_0123456789_030_0123456789_031_0123456789_03
2_0123456789_033_0123456789_034_0123456789_035_0123456789_036_0123456789_037_0123456789_038_0123456
789_039_0123456789_040_0123456789_041_0123456789_042_0123456789_043_0123456789_044_0123456789_045_01
23456789_046_0123456789_047_0123456789_048_0123456789_049_0123456789_050_0123456789_051_0123456789_0
52_0123456789_053_0123456789_054_0123456789_055_0123456789_056_0123456789_057_0123456789_058_0123456
789_059_0123456789_060_0123456789_061_0123456789_062_0123456789_063_0123456789_064_0123456789_065_01
23456789_066_0123456789_067_END
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11742887
Maybe listctrl "wordwrap" feature, as an alternative you can owner-draw your control.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11743251
Perfrom a search here for owner draw list control, there should be numbers of example code.  (I only tested with ca 600 chars but it did work).
0
 
LVL 3

Author Comment

by:tma050898
ID: 11743314
Hi Andy,

Thanks. I've written chapters in my books on custom and owner drawn controls so I know how to do that.
However, I was hoping to find another way of circumventing the apparent text-length limitation.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11743361
This is just a guess but maybe standard list control just has a 255 char buffer.  I forgot to say mine was owner data as well as owner draw.  Maybe just having it as owner data would suffice.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11743635
Or it might be that the api has that restriction and if I can access the lv's internal buffer i can manually set the text value.

This is what I'm looking for a definitive answer on.

IOW, I can't go back to the client and say that I think there's a limit and I think it can't be overcome. I need to know that for sure
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11743760
I have not found any limitation in Visual C++ documentation, WinAPI documentation, all the internet, nor in MFC source code.
If your data is so long, how do you will see in a Listctrl anyway? It will not feet on screen width.
You have not answered me if you have seen it correctly in a messagebox.

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11743837
Try owner data, that should circumvent any internal limitation (if there is one) as it forces the list control to query for the text
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11743862
You have to choices: ownerdata and ownerdraw, ownerdata still can truncate your data (*) so ownerdraw will work always.

(*) You can make a test. Use SetItemText() and retrieve again with GetItemText(), and see if string is truncated.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11744293
[jaime] I have not found any limitation in Visual C++ documentation, WinAPI documentation, all the internet, nor in MFC source code.
This is why I posted the question. I also looked in all those places and I'm wanting to see if anyone knows for certain what the limitation is and how to circumvent it.

[jaime] If your data is so long, how do you will see in a Listctrl anyway? It will not feet on screen width.
The client wants it.

[jaime] You have not answered me if you have seen it correctly in a messagebox.
I appreciate you trying to help, but so far you've asked two questions that were addressed in the original question and proposed a solution that I mentioned in the beginning that I didn't want to use.
I've also stated several times that I've verified that the data is being passed in its completion to the SetItemText function.
Pleae keep in mind that I've been using VC since 1.5 (MFC 1.0) and have written 3 books on the subject so obviously I've verified all the basics before posting here.

What I'm looking for is someone who might know how to directly access the list view window's internal buffer or know definitively (not guessing) that it can't be done.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11744316
I am sure there is no way to access listctrl internal buffer, because that is made trhough WM_SETITEMTEXT.
Even CListCtrl does it this way (just have to see MFC source code), so I think there is no person who can talk about this with exception of Microsoft guys.
If you contact them please tell us about the answer.
BTW. I have worked with VC since first version too, and also MS C Compiler, but as I have said, IT IS NOT A MFC PROBLEM, but can be a WinAPI bug or limitation.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11744325
Sorry about my last post, it is LVM_SETITEMTEXT.
Here is the implementation of MFC SetItemText():

BOOL CListCtrl::SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
{
      ASSERT(::IsWindow(m_hWnd));
      ASSERT((GetStyle() & LVS_OWNERDATA)==0);
      LVITEM lvi;
      lvi.iSubItem = nSubItem;
      lvi.pszText = (LPTSTR) lpszText;
      return (BOOL) ::SendMessage(m_hWnd, LVM_SETITEMTEXT, nItem, (LPARAM)&lvi);
}

As you can see, it is impossible that MFC is truncating, that's why asked to you to settext and then gettext to verify if a truncation is made
(by WinAPI, of course).
0
 
LVL 3

Author Comment

by:tma050898
ID: 11744347
[Jaime] BTW. I have worked with VC since first version too, and also MS C Compiler, but as I have said, IT IS NOT A MFC PROBLEM, but can be a WinAPI bug or limitation.

I wasn't doubting your experience. I was simply stating mine so that you would know that the basics have been covered.
After all, you're just trying to help and have no way of knowing the experience level of each person you're trying to help so I was letting you know to aid you in your suggesitons.

I never said it had anything to do with MFC. It's a well-known fact that MFC wraps the common controls with nothing more than a very thin wrapper that sends the messages to the
window - just as we would in a Win32 API application.. However, that fact doens't mean that there isn't a way of accessing the list view's internal buffer in memory.

Anyway, as you said, this is obviously not something trivial so I will call a friend on the VC++ team on Monday and hopefully he'll be able to help me (doubtful as his job is the compiler)
or at least get me in touch with someone that knows the answer. I'll post here what I find out .

Thanks everyone for trying to help!!
Tom Archer


0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11744407
Tom,
I have reviewed WINE implementation too and have not found any size limitation. Even drawing function is made with DrawText(...., -1, ...)
Look at http://source.winehq.org/source/dlls/comctl32/listview.c#L3673
Are you sure it is not a column width/clipping problem instead of a string truncation problem?
0
 
LVL 3

Author Comment

by:tma050898
ID: 11744481
Yep. This is precisely my point; that it's probably the api to set the text that has the limitation - not the drawing code.
Having written a list view control many years ago before it was a common control (in OS/2), there's really not that many ways you can go :) so
The text is just basically rendered by drawing it on the window's client area. Therefore, the question remains, is it possible
to access that internal buffer by another means - other than setwindowtext (or the lvm_setitemtext).

Regarding clipping, I checked that first, but it's not that either.
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
ID: 11744627
I have some dudes now. When you use owner data, you have to manage WM_GETDISPINFO message.
This is the implementation recommended by Microsoft:

// some code here, not important
if (pItem->mask & LVIF_TEXT) //valid text buffer?
{
    switch(pItem->iSubItem){
        case 0: //fill in main text
            lstrcpy(pItem->pszText, m_Items[iItemIndx].m_strItemText);   <---- Here
            break;

            //etcetera
    }
}

They recommend us to use lstrcpy, so control as an allocated buffer, but it is not specified buffer size.
So what is buffer size? can't be unlimited.

Chris Maunder take a different aproach to handle this message:
http://www.thecodeproject.com/listctrl/listview_callback.asp?print=true
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Author Comment

by:tma050898
ID: 11744851
Thanks Jaime. As I mentioend, I definitely know how to write owner and custom draw controls.

However, what's ironic is that even though Chris and I started and ran CodeGuru together, I had long ago forgotten his excellent article on this subject.
It still amounts to an owner data control, but it's looking like that's my only option.

By the way, while we're not getting to the answer I had been hoping for, I do appreciate you taking so much time in helping me.

Cheers,
Tom Archer
0
 
LVL 3

Author Comment

by:tma050898
ID: 11744915
Hi lunchy,

I've changed my mind. While I didn't get the answer I was looking for, Jaime worked very hard and did point out an article I had forgotten that I will probably end up using.
In addition, this solution - once PAQ'd - might also help others that run into the same problem.

Therefore, I'd like to keep this open where I will eventually accept Jaime's answer (I'm only waiting on a response from MS in case I can add more info
to this question).
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11745420
I must be missing something - the article looks like owner data, what exactly is the difference?
0
 
LVL 3

Author Comment

by:tma050898
ID: 11745426
Jaime said himself that it's basically just another way of doing owner-data.
Anyway, the comments at the bottom of the article state that this technique also can't write more than 260 chars.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11745446
>Anyway, the comments at the bottom of the article state that this technique also can't write more than 260 chars.
Yes, that's the point, there is evident that control has some kind of buffer (not just a pointer to a buffer) and this buffer must have a size limitation
(260, 1000, 2000, etc.) like every standar C string buffer.
The problem is that I have spent more than an hour and have not found any other page in the Internet where this limitation is mentioned.

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11746154
Back to an earlier comment from me.
I have here an owner draw/owner data and it displays at least 600 chars, I have not tested it further as I am not being paid for this.  Like Jaime (and the other experts) I offer my experience freely.
You are experiencing a restriction, apparently undocumented, with a standard list control but having it as owner draw/owner data should do what you require.  I wait with interest what your contacts inside microsoft come back with wrt a buffer limit.
Just as owner data MAY be satisfactory but I haven't tested that.  (Jaime is of the opinion that just set as owner data will run into a restriction).

You have said you are an accomplished and experienced programmer.  You should be able to quickly test if owner data can perform as you require.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11746308
What is your point, Andy? You'll notice that it was *me* that stated that owner draw would work.
However, I also stated that but that I don't want to use it.
You then replied that owner draw would work.

Regarding your remark about not being paid. I never said you were and never implied that you shoudl do more.
In fact I've been very specific to thank you both for your time so again, I have no idea what you're carrying on here about.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11746324
Hey Jaime,

I found this on the RDN (Russian Developers Network)

pszText
If the structure specifies item attributes, pszText is a pointer to a null-terminated string containing the item text.
If the structure receives item attributes, pszText is a pointer to a buffer that receives the item text.
Note that although the list-view control allows any length string to be stored as item text,
only the first 260 characters are displayed.

This was what i wanted for my client - a *definitive* answer.

Thanks again for your help, Jaime.

Obviously, I'm going to have to owner draw this, which means rearchitecting some of the my
database library's demo app to make the data available class-wide, but that's the only option here.

Anyway, I'll now accept your comment as an answer as reward for all the time you spent helping
me try and track this down and I think some of this discussion will help others with the same problem.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11746330
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11746365
Ahh, those russian pages, I always skip them but I am sure there have more technical info that we expect.
It is unbelievable that I have not found the Microsoft page. In spanish we say something like:
"The best hunter loss the bird"
Good luck,
Jaime.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11746378
:) Since I speak Russian (and Spanish), I frequent them quite a bit.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11746404
tma, please reread your question and my comments.  The very first mention of owner draw working that I see was by ME.  You just said you didn't want to use it (at that point I didn't know if that was because you couldn't or not).
Being paid - jaime explicitly says 'The problem is that I have spent more than an hour' in a comment, I was just saying the experts comment voluntarily.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11746419
Actually...

The comment from me at Date: 08/07/2004 06:25AM PDT stated,
"...I need to know if there's a way to circumvent that limitation without resorting to owner/custom draw."

You then responded 16 minutes later (Date: 08/07/2004 06:41AM PDT),
"Also I have just quickly butchered (on owner draw) list and displayed ca 600 char long strings in it apparently without a problem "

I'm certainly not saying you did that intentionally. You probably just didn't read my comment completely.
However, the point is that you still offered a solution that I had just stated I didn't want.

Regarding the paid comment, sorry. I thought your remark was directed at me since you didn't mention Jaime.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11746431
>Being paid - jaime explicitly says 'The problem is that I have spent more than an hour' in a comment
I use to spend more than an hour in at least 2 or 3 hard questions every week, not related to any payment,
no need to anybody recalls me that EE is voluntary. Have read the MA, but if my expression is incorrect in english please advice me.
Anyway, thanks,
Jaime.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11747596
I did (?) I see his comment a couple of pages up as "Accepted Answer" and I graded him 'A'
:confused:
0
 
LVL 3

Author Comment

by:tma050898
ID: 11747604
Jaime's post of Date: 08/07/2004 03:31PM PDT shows a Grade of A. Is there something additional I need to do?
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11759873
Jaime: One way of interpreting your comment is that you personally now have a problem and that problem is you have spent an hour of your time working on this question.  I can understand a comment like 'I have given you the answer, now give me the points' but a comment like 'I have spent an hour on this, now give me the points' is certainly over the top.  Also what is an hour.  I once did a small demo to demonstrate a critical functionality for a client and sent it back less than an hour after we discussed it on the phone.  He was stunned - another firm had quoted three days for that functionality, I got the contract and a lot more work from him.  (From seeing your contribution here at EE I believe you aren't in this three day catagory).

tma: I had falsely taken that to mean you didn't know if owner draw would work.  (A lot of questions at this site are from novices) Sorry.  
ps. I can understand you wanting to keep this question available for others but why not ask the moderators to PAQ it and refund points if you had not got an answer.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11761037
Andy: No problem. Reading the question in that vain, I can see how it might come across like that.

Andy & Jaime: By the way, I'm working on a list view control that will automatically display a button with an ellipses when the text is greater than 250 chars. Clicking on that button will display the text in a separate window. If you guys are interested, drop me a line (tom@archerconsultinggroup.com) and I'll send it to you when I'm done.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11761493
Thanks but no need.  I could do that without a problem  - An alternative would be to display the extra text as a sort of tooltip (vertically scrollable).  The user wouldn't even need to click the button, just put the mouse there.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11762373
Thank you tma, I have not found a client yet with that requirement but maybe some day.... Or maybe will be better to you to post it to codeproject or codeguru.
I think it must be mandatory for every EE member to post a little resume to know who are we talking to. But was my mistake not reading tma resume (or he has posted it recently?) I could had not post the first 3 or 4 comments.
Anyway, nice to meet you, Tom.

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11762490
Jaime: 'I think it must be mandatory for every EE member to post a little resume to know who are we talking to'  Sounds like a good idea, or at least next to questioners name a self ranking <novice, beginner, intermediate...>.  Post it in the community support area as a suggestion.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11762608
>Post it in the community support area as a suggestion.
I have posted a couple of ideas to CS but I feel it is very hard that they will take it, considering amount of them, and that them are mixed with other unrelated posts.
Please let me make you a suggestion: I guess you are not native english speaker as me, I had bad experiences trying to interpret (or mis-interpret) colloquial (non-technical) expressions from other members, specially if they are not native english speakers too, so, don't do.
Best regards,
Jaime.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11763029
>>>But was my mistake not reading tma resume (or he has posted it recently?)
It's been there since I joined ExEx - back when Linda and Dan started it about 5 years ago or so.

>>>Or maybe will be better to you to post it to codeproject or codeguru.
I write the ".NET Tips & Techniques" column for CodeGuru, but this is Win32/MFC code. I'll probably post it to my new site - http://www.realdevs.net - we're new and need the content more than Chris does :)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11763132
I will subscribe to your page Tom, please take account of this suggestion:
I think codeproject is really nice because of it clear article organization (the left side bar) and the fact that most of discussions are inside articles itself. It is "article-based"
Codeguru was similar once, but now is very confusing, also its search feature is terrible.
Good luck with your page,
Jaime.
0
 
LVL 3

Author Comment

by:tma050898
ID: 11763743
>>>I will subscribe to your page Tom,
Great. Thanks!

>>>
please take account of this suggestion: I think codeproject is really nice because of it clear article organization (the left side bar) and the fact that most of discussions are inside articles itself. It is "article-based"
<<<
Absolutely agreed. I just started with them a week ago, but definitely plan on changing a lot of what you see for just the reason you noted.

>>>Codeguru was similar once, but now is very confusing, also its search feature is terrible.
Don't remind me :( Zafir, Chris and I built that site and when Z sold it to EarthWeb, they basically destroyed it.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now