Hi,

should be a simple question at first glance, but apparently there is no documented way to get the text length of a (sub)item of a listview in report mode without getting the text as well. Or am I wrong?

Japheth
Posted on 2003-01-20 05:58:22 by japheth
Same problem here. :(
Posted on 2003-11-13 07:06:41 by AceEmbler
This is crazy since you have to speciffy buffer to contain subitem text to count it's length. Realy i would like to meet guy who designed ListView Report.
I will consider Custom ListView in near future since default one so lack.

Is there a way to get acces to the place in memory with ListView informations ??
Posted on 2003-11-13 12:38:19 by AceEmbler
regards
Posted on 2003-11-13 20:24:57 by jefeng
There's a way to get the length of the item text without retrieving the text :) This cannot be done for subitem...
  [COLOR=teal][b];(C) 2003 Morris :)[/b][/COLOR]

[COLOR=blue][b]invoke[/b] SetFocus[/COLOR],hListView
[COLOR=blue][b]invoke[/b] SendMessage[/COLOR],hListView,[COLOR=blue]LVM_EDITLABEL[/COLOR],iItemNumber,0
[COLOR=blue][b].if[/b][/color] [COLOR=orange]eax[/COLOR]
[COLOR=teal][b];we have the hWnd of the edit box which is used to edit the item, so why not get the text lenght? :)[/b][/COLOR]
[COLOR=blue][b]invoke[/b] SendMessage[/COLOR],[COLOR=orange]eax[/COLOR],[COLOR=blue]WM_GETTEXTLENGTH[/COLOR],0,0
mov iTextLength,[COLOR=orange]eax[/COLOR]
[COLOR=blue][b].endif[/b][/color]

[COLOR=teal][b];cancel edit[/b][/color]
[COLOR=blue][b]invoke[/b] SendMessage[/COLOR],hListView,[COLOR=blue]LVM_EDITLABEL[/color],-1,0
This method however produces some unwanted effect (selected listview item flashes).
Posted on 2003-11-14 01:20:54 by Morris

regards



Dont tell me.......
No i will not belive it :tongue:


That's a good one Moris i will remember it.



Somebody knows max length of ListView Item text ???
Posted on 2003-11-14 16:56:49 by AceEmbler
you can save the Text's Lenght as the item's data (LPARAM lParam; // 32-bit value to associate with item ) (if you don't use it).
Posted on 2003-11-14 17:12:30 by wizzra

you can save the Text's Lenght as the item's data (LPARAM lParam; // 32-bit value to associate with item ) (if you don't use it).


Nice thanks.
I'm using lParam but i think that i can spare 16 bit for length.

Maby it was to early to flame that control so much :tongue:
Posted on 2003-11-14 17:50:40 by AceEmbler
Hi, guys. You might find this interesting...
There is another way to do it, based on a trial and error approach.
http://www.asmcommunity.net/board/showthread.php?threadid=14524&highlight=get+text+length
Posted on 2003-11-14 20:07:05 by QvasiModo
Qvasimodo,

The original question was:
Originally posted by japheth
apparently there is no documented way to get the text length of a (sub)item of a listview in report mode without getting the text as well. Or am I wrong?


The trial-and-error method requires to retrieve the text to check its length.
Posted on 2003-11-15 03:48:00 by Morris
Duh... :o
:stupid:
Posted on 2003-11-15 16:32:29 by QvasiModo
Originally posted by wizzra
you can save the Text's Lenght as the item's data (LPARAM lParam; // 32-bit value to associate with item ) (if you don't use it).
This will work only for item's text, but not for subitems' texts (subitems do not support the LVITEM.lParam member).

Anyway, I have some idea about getting the length of (sub)item's text without getting the text. I'll publish it when I do some tests :)
Posted on 2003-11-15 17:55:36 by Morris
Hi Morris,

yes indeed, but you can do a little trick.
if your text is not over 256bytes and u have x<=4 columns, u can use the LPARAM lparam to save upto 4 diff column's text lengths (1main column + 3 subitems) for each row.

15385FFFh ;)

item text = 15h
sub item 1 = 38h
sub item 2 = 5Fh
sub item 3 = FFh
Posted on 2003-11-16 12:24:37 by wizzra
but if u have only 256 max length you can provide such a short buffer without hessitation plus speed will be satysfying also.
Posted on 2003-11-16 13:08:32 by AceEmbler
If you really need more text and/or subitems, you can allocate enough memory to store the lenghts of each string and place the pointer in lParam. (I hope this makes up for my useless post before :grin: ).
Posted on 2003-11-17 11:29:26 by QvasiModo

If you really need more text and/or subitems, you can allocate enough memory to store the lenghts of each string and place the pointer in lParam. (I hope this makes up for my useless post before :grin: ).


Idea is good but it will make it more complex, we are serching the easiest way to do this.

1. You will not know how many items there will be so who knows how big the buffer will be (BTW it's realy bugging me when i cant specify exact buffer size).
2. There will be a problem with SubItems maby we will add new columns later.
3. A lot of new ListViews==A lot of new buffers.
Posted on 2003-11-17 12:31:21 by AceEmbler
You have a point, it would be more complex. However all the other problems can be solved... if you add a new column, you have to reallocate all of your "buffers". This may be a problem, though, depending on how you're allocating this data...

As for not knowing the size of the array of pointers, it's enough to store the size in the first DWORD. :)
Still the idea is only good for a fixed number of columns, though. Otherwise it's more trouble than it's worth. :(

Hey, but at least I said something useful this time, it's an improvement. :grin:
Posted on 2003-11-17 12:54:27 by QvasiModo
Originally posted by AceEmbler
Is there a way to get acces to the place in memory with ListView informations ??


Hmmm, it took me a while to do some research on this... Are you still interested? :)
Posted on 2003-12-01 17:28:34 by Morris
Naturally :)
Posted on 2003-12-02 07:50:48 by AceEmbler
Well, basically to get to the internal ListView structure you simply have to
invoke GetWindowLong,hListView,0
But here's where it starts to be complicated. From version to version this structure has ben changed, and to my current knowledge, there are seven variants of this, let's call it, LV_DATA.
I've checked comctl32.dll versions from 4.00.950 to 6.0.2800.1106 (with some exceptions, see the attachment). I did not bother to demystify all members of the LV_DATA structure, only those that were easy to guess by their contents. Maybe in the future I'll look at it a bit closer. Any comments welcome.
Posted on 2003-12-03 02:23:00 by Morris