Can anyone suggest sample code to use a grided list box with a database? This is to unfortunately, replace the many Einhugur Style Grids in my very large project.
Specifically, adding rows from a db, and adding icons in certain cells next to data from a database.
Make a container control with a listbox subclass and 2 scrollbars
make a property in the CC that contains the sql request to your database
using the “LIMIT” and “OFFSET” options of the SELECT command, you can draw the list with only the visible part of the listbox that is redrawn.
limit = number of visible rows
offset = value of the vertical scrollbar
it’s not easy to do, it took me some months to make it work flawlessly but it can be done (I did it !)
that way you see almost no difference to display a local database with 100k rows, or a distant one because you search and display only 50 rows at a time.
I cannot get an app to compile to 64 bit using that object. Maybe I missed something else - has anyone been able to make an app compile to 64bit with the stylegrid?
I went through this last year for the same reasons (Retina and upcoming 64-bit support), had to rip out about 5 or 6 StyleGrids and replace them with ListBoxes. You can show a pic in the CellBackgroundPaint and CellTextPaint events, fairly easy there should be examples all over the place in the forums and docs. My work does not involve a huge number of rows returned from a DB, so I can’t comment on how well that part will work for you. But under 1000 rows, the ListBox is just about instantaneous for displaying data from a database.
I think I read your post elsewhere about making the change. In my case, the record counts are all very low < 100. Do you know where I can get a sample that uses a db to fill a gridded listbox?
I just do a query on the database, returning the minimal amount of data needed for whatever view of the data I am showing and loop through the recordset, adding a row to the ListBox and then fill in the information you want to show. I use the RowTag for the DB record identifier so that I can lookup and make user edits easy. I use CellTags for flags that I can then react to in the two Cell paint events (things like pics). The Xojo Docs should show you how to both query the database (which I am sure you would already be doing to fill in the StyleGrid?) and also how to fill in the cells and celltags of a listBox, if you look in the ListBox section.
[quote=225023:@Beatrix Willius] @Ivez: any plans to make your code public?[/quote]
sorry no plans like that for now, there are too much imbricated code and modules to release it alone.
and seeing the time I spend on it I would surely sell it
Does anyone know why there are 2 AddRow methods to the Listbox?
Even in the examples there are 2 methods. It works in the examples, but when I try to use it .AddRow the compile says there are 2 and doesn’t know which to use.
Can anyone tell me what I am doing wrong with this?
Thanks,
Tim
Thanks again everyone.
I found the problem with my original code - two of the records are integers and needed the Cstr conversion. It was missing. The compiler threw an incorrect error - at least that is what it appears to be.