Forum > Databases
Updating data from a KDBGrid to SQLite
GetMem:
@heebiejeebies
--- Quote ---By the way, I didn't bother including it because I figured my code is probably completely wrong from the ground up
--- End quote ---
Always attach a demo project, otherwise we just shot in the dark, it does not matter if it's wrong or not and don't worry we all make mistakes.
--- Quote ---Halp please
--- End quote ---
Here you go:
- download then extract attached project
- copy sqlite3.dll to your project folder, make sure the bitness is correct depending on your Lazarus/FPC version
- compile/run project
PS: Please note that I never worked with KControls and KDBGrid in particular, maybe there are better ways to achieve the same thing.
heebiejeebies:
--- Quote from: Zvoni on February 06, 2023, 11:12:27 am ---Does the same happen with a "regular" DBGrid?
--- End quote ---
That was another option that I tried, which again resulted in lots of lost hair. Basically I couldn't get a regular grid to load the data, it just showed (MEMO) in all the cells.
heebiejeebies:
--- Quote from: GetMem on February 06, 2023, 01:10:17 pm ---@heebiejeebies
--- Quote ---By the way, I didn't bother including it because I figured my code is probably completely wrong from the ground up
--- End quote ---
Always attach a demo project, otherwise we just shot in the dark, it does not matter if it's wrong or not and don't worry we all make mistakes.
--- Quote ---Halp please
--- End quote ---
Here you go:
- download then extract attached project
- copy sqlite3.dll to your project folder, make sure the bitness is correct depending on your Lazarus/FPC version
- compile/run project
PS: Please note that I never worked with KControls and KDBGrid in particular, maybe there are better ways to achieve the same thing.
--- End quote ---
THANK YOU GETMEM! :) You are an absolute legend among legends.
Now, I just need to pull it apart and figure out what I was doing wrong. Will probably be back with questions :D
Zvoni:
--- Quote from: heebiejeebies on February 07, 2023, 07:17:10 am ---
--- Quote from: Zvoni on February 06, 2023, 11:12:27 am ---Does the same happen with a "regular" DBGrid?
--- End quote ---
That was another option that I tried, which again resulted in lots of lost hair. Basically I couldn't get a regular grid to load the data, it just showed (MEMO) in all the cells.
--- End quote ---
And if you've just searched the Forum, there are enough answers for the "(MEMO)"-Thing for DBGrid in combination with SQLite....
The easiest being
--- Code: SQL [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SELECT CHAR(SomeTextColumn) AS Field1 FROM SomeTable
heebiejeebies:
--- Quote from: Zvoni on February 07, 2023, 08:58:57 am ---
--- Quote from: heebiejeebies on February 07, 2023, 07:17:10 am ---
--- Quote from: Zvoni on February 06, 2023, 11:12:27 am ---Does the same happen with a "regular" DBGrid?
--- End quote ---
That was another option that I tried, which again resulted in lots of lost hair. Basically I couldn't get a regular grid to load the data, it just showed (MEMO) in all the cells.
--- End quote ---
And if you've just searched the Forum, there are enough answers for the "(MEMO)"-Thing for DBGrid in combination with SQLite....
The easiest being
--- Code: SQL [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SELECT CHAR(SomeTextColumn) AS Field1 FROM SomeTable
--- End quote ---
Thanks, I already use that code elsewhere to deal with the same problem (I think it was you that told me about it previously). But I also have other issues with DBGrid, such as DBGrid.DataSource.DataSet.Last and DBGrid.DataSource.DataSet.First not working, so I'll just stick with KDBGrid. GetMem's code works well!
A couple of questions:
In the example project, the code validates one of the fields to ensure it is a valid integer. Is there any way to validate input from the grid to ensure it is a valid date? and
One of the drawbacks of KDBGrid is that it doesn't allow you to set individual columns as read only. Any idea how to work around this? Maybe select a different column using FocusCell as soon as the user enters that column. I've tried this using the OnEditorSelect event, and while the event does fire instantly as expected, FocusCell doesn't actually do anything in this instance.
Thanks heaps everyone :)
Disregard. I'm going to keep one of my grids as editable and for the troublesome one, I'm just going to lock the text and pop up an editor instead.
Navigation
[0] Message Index
[*] Previous page