IonicWind Software

IWBasic => The Roundtable => Topic started by: srod on July 31, 2007, 05:30:33 AM

Title: Editable cells in a listview control
Post by: srod on July 31, 2007, 05:30:33 AM
Hi,

as a good means of getting to grips with EMBasic, I grabbed one of my Purebasic utilities almost at random and converted it to EMBasic (whilst beefing it up a little). I've got to say that with the assistance of the EMB help manual and these forums, it was a breeze. EMB appears very solid indeed (and I love these c-style pointers! Never realised just how powerful pointers could be before now!)

What we have then is a little utility that allows any cell in a listview control to be directly edited by the user. It's quite simple and whilst not in the same league as a grid control, it's quite effective anyhow and quite suitable for those applications just requiring basic editing of cells etc.

It works as follows:

Basically, a Windows list view control allows you to edit the labels in column zero if you set the LVS_EDITLABLES style and, at a minimum, process the LVN_ENDLABELEDIT message. What my library does on intercepting a double-click on a valid cell, is instruct Windows to edit the corresponding label in column 0, but before Windows has a chance to position the edit control used to actually edit the label, the library manages to grab a hold of the control and reposition it over the selected cell etc. On completion of the editing process, I just switch the text in the cell for that in the edit control etc. I also take steps to scoll the listview if the user double clicks a cell which is only partly visible.

It's not perfect, but as I say it is simple.

http://www.purecoder.net/List View editable.zip (http://www.purecoder.net/List View editable.zip)

Note that for various reasons, to use this library with any listview control, you must set column zero to have a zero width. This is to prevent some poor behaviour on Windows part when the user clicks a row.  See the demo program enclosed in the zip.

Stephen.
Title: Re: Editable cells in a listview control
Post by: mrainey on July 31, 2007, 06:29:38 AM
Thanks for that one.
Title: Re: Editable cells in a listview control
Post by: srod on July 31, 2007, 06:34:29 AM
Quote from: mrainey on July 31, 2007, 06:29:38 AM
Thanks for that one.


You're welcome. As I say, coding this has taught me a lot about EMBasic!  ;D
Title: Re: Editable cells in a listview control
Post by: Haim on July 31, 2007, 06:48:03 AM
Hello,
Somehow the link does not work for me.
I get a message that the link is invalid

Any suggestion for what I should do?

haim
Title: Re: Editable cells in a listview control
Post by: srod on July 31, 2007, 06:50:07 AM
Uhm, for some reason nothing happens if I click the link!

Still, works if I copy and paste the url etc. Try that.
Title: Re: Editable cells in a listview control
Post by: Rock Ridge Farm (Larry) on July 31, 2007, 06:50:39 AM
Cut the link and paste it to your browser - I had the same problem after the last firefox update.
I am also having problems with many web sites today - Could the web be sick?

Title: Re: Editable cells in a listview control
Post by: srod on July 31, 2007, 06:51:13 AM
Try now.
Title: Re: Editable cells in a listview control
Post by: Haim on July 31, 2007, 07:05:11 AM
Thanks,
Worked this time.

Haim
Title: Re: Editable cells in a listview control
Post by: splakidas on August 01, 2007, 08:58:37 AM
if i change the number of columns from 30 to 400


For col = 1 To 400
    CONTROLCMD  w1, 1, @LVINSERTCOLUMN, col, "Col "+Str$(col)
    CONTROLCMD  w1, 1, @LVSETCOLWIDTH, col, 100
Next col


then you are not able to see numbers greater than 328 on the top of the listview
it is possible to work ?
Title: Re: Editable cells in a listview control
Post by: srod on August 01, 2007, 09:19:18 AM
Quote from: splakidas on August 01, 2007, 08:58:37 AM
if i change the number of columns from 30 to 400


For col = 1 To 400
    CONTROLCMD  w1, 1, @LVINSERTCOLUMN, col, "Col "+Str$(col)
    CONTROLCMD  w1, 1, @LVSETCOLWIDTH, col, 100
Next col


then you are not able to see numbers greater than 328 on the top of the listview
it is possible to work ?


A windows limitation of the header control is that it's total width must not exceed 32767 pixels (16-bit). So it is not the number of columns which is the problem, but the total width of all the columns.  In fact you'll see that 327 columns each of width 100 pixels renders correctly (total width 32700) but the 328th header item does not.  As soon as you exceed this limit then the header begins to misbehave!  This is the case for all listview controls.

Nothing we can do therefore except remove the header from the listview control and use the first row of the listview to simulate the header cells.

The reason for all this is that the header control actually has a client area equal in size to the sum of all widths of the header cells. This seems a strange way of doing it to me, probably a throw back to earlier versions of windows. I do think the header control is due a revamp.  :)


Title: Re: Editable cells in a listview control
Post by: JimH on August 01, 2007, 09:52:56 PM
Stephen -

Thanks for the interesting code - and especially for the liberal comments throughout!

It is so much easier to learn when the coder tells you what he's doing instead of making you guess.  :P

   <*> Jim
Title: Re: Editable cells in a listview control
Post by: srod on August 02, 2007, 03:32:08 AM
Quote from: JimH on August 01, 2007, 09:52:56 PM
Stephen -

Thanks for the interesting code - and especially for the liberal comments throughout!

It is so much easier to learn when the coder tells you what he's doing instead of making you guess.  :P

   <*> Jim

You're welcome Jim.