PDA

View Full Version : Best way to make a scrollable multi-column listbox or grid control?



sami
12-08-2012, 05:33 AM
I've had a bit of a search, but haven't found anything. (Also, search in the forums seems a tad broken as stuff 5 pages ago I've posted last year doesn't pop up despite unique keywords)

I'm sure someone has made a ctllistbox multi-column (is there hidden arguments to this somewhere please!) or a grid control? I really really don't wanna make my own out of 2 dimensional array of textboxes. It wouldnt be scrollable and adding multi row select would be painful. Please tell me there is someone who has done this or knows how to (hopefully easily). Thanks for any tips or pointers!

sami
12-08-2012, 09:12 PM
I was truly hoping that cltlistbox has a 2nd column feature like in the Modeler points info panel - by pressing the "i" key with points selected - but I can't figure out if there was any way to do this. I hoped it was as simple as adding an array as an item to the list and if there were 2 elements in the item array then it would automatically make a new column. but I'm stumped with that.

Is that possible in any way with this control or an undocumented other one?


Otherwise, I have started creating 2 ctllistboxes side by side to simultate a multicolumn spreadsheet - though I can't figure out the event or callback (if there even is one) which allows me to synchronize the scrolling of both listboxes. I hopefully was trying to determine if list 1 is scrolling, then set the top row or scroll to the row in listbox 2 that matches listbox 1. I can highlight/select the row 2 of listbox 2 when row 2 is clicked in listbox 1, and vice versa so at least the highlighting syncs up, but the real trick is getting the scrolling to sync.

Any ideas?? thanks!

evenflcw
12-09-2012, 08:55 AM
I believe I've also tried overlapping listboxes (the cells typically draw over the scroller). Looks and works great until you scroll. I do not believe there is a way to synch the scrolling, so it is only viable for fixed grids. I suppose one could do a fixed grid, make a custom scroller, and turn the values manually. Wouldn't be pretty though, and listbox callbacks allover the place.

The common way to do multicolumn listboxes in lscript is to just use one listbox and try to fake the columns. Naturally this still only gives you single row selection, rather than per cell. So if you have several different values per row, you have to have an alternative workflow after selection is made to set the respective cell values. If you only need to display information (over multiple columns), and only toggle one value, this method should work well though. You can see example of this in my MultiService - not viewable in the demo video which is on an older version. The downloadable version, displays two "columns" (see attachment), one for the active state of a command, the other for the name of the command, double clicking anywhere on the row toggles the active state. You can see even more columns in Lernies/Faulknermano's Janus, which I believe also uses standard listboxes.

I'll also mention that it is possible to write a multilist from scratch in lscript. For the average lscript however, this would be a/the major part of the project. I might or might not provide something, an old project, about 80% done. Still has to be finished and still not sure how to release/license it.

sami
12-09-2012, 04:17 PM
Thanks, that helps! I assume the default font isn't monospace, so maybe I could use drawtextwidth to see how long a string is in pixels and try to fake real, lined up columns that way? I really don't feel like writing a real grid from scratch in a viewport control, that would be massive - i'm spoiled having used the jquery component jqgrid which has in-cell editing, drop downs in cells, sub-rows, and everything.

I'll revisit whether there is another way to show what I'm after here. I also worry that writing one yourself means you have to handle large lists with memory paging or something? Lazy loading for only visible rows? That's sounds time consuming for a control that I just need as a UI element.

But if you have something 80% done and I can help with it, then maybe it's worth collaborating? And obviously you can decide how you want the licensing to work for that. So far everything I've done with LW plugins has been freely given back to the community, though I'm working on a good idea now that might have commercial potential as a plugin (I haven't seen anything like it around) and a grid could be useful for its UI in one place, so that should be taken into consideration if you've put alot of time into that 80% grid and are wondering about my use of such a thing... :)

evenflcw
12-09-2012, 05:43 PM
Unfortunately drawtextwidth only works in the draw context, if I remember correctly or as you've probably discovered. To fix that I created the attached library for myself and use settextwidth to insert spaces inbetween words so I get the fake columns aligned somewhat correctly.

Yes. "Lazy loading" (ie only loads data showed) was necessary, but not a big deal.

Collab probably not necessary for finishing it. 15% of those 20% is the scrolling and as I remember it wasn't much to worry about, the rest is testing and tweaking. But I could use a beta tester. :) The framework or whatever you could call it can be compiled and imported for reuse (as many tables as you like). Maybe we continue this part of the discussion in private.

evenflcw
12-09-2012, 05:52 PM
Mind you, minisliders and popups are unfortunatly not possible to recreate (well) in lscripts, as mousemoves are limited to screen and you can't draw outside lscript panel. It might be possible to exceed both limitations with c-lscript-extension, but then obviously it's not as platform independant anymore.