[SOLVED] Readonly columns in a DbGrid lazarus / 16-Databases ---------------------------------------------------------------------- Hopestation · 2015-12-14 10:48 Hi. I am using Lazarus Version #: 1.4.4, FPC Version 2.6.4. I have a DBGrid in which I want to allow writing in only 2 columns. I have set the ReadOnly property in these to False and to True in all the others. When I try to write in one of the permitted columns nothing happens. Checking the DbGrid properties I found dgEditiing was False so I set it to True, but now I can write in any column, the ReadOnly status is ignored. Am I doing something wrong. Also, when I modify a cell the focus automatically moves to the next column to the right. If I want to make more changes they will be in the same column. I can't find a property to set the move from Right to Down. Does this exist? Thanks. ---------------------------------------------------------------------- madref · 2015-12-14 14:50 For as far as i know its either write or readonly You can try to solve it by splitting your grid up in two parts the part thats readonly and the part thats writable. Also make two DBgrids and make sure that everything correspond and your problem is solved. ---------------------------------------------------------------------- mangakissa · 2015-12-14 17:29 It should be working. Otherwise set your field in the dataset to readonly. It's almost the same thing. Using two grids is nonsense. Actually using the DBGrid as a viewer is much better and use DBEdit for modifying. But for two columns it's overrated. ---------------------------------------------------------------------- Hopestation · 2015-12-14 21:26 Thanks for your reply mangakissa, that's the way I'd like to go, but I don't know how to set the field to readonly in the dataset. I created the database as a .dbf file in OpenOffice SCalc, using the field names in the first row, including the field size, e.g. Name,C25. I noticed in the Tutorial, http://wiki.freepascal.org/Lazarus_Tdbf_Tutorial, that I can have a variety of field types including Boolean, but again, I don't know how to do that either. Can you explain how this is done? Thanks. ---------------------------------------------------------------------- mangakissa · 2015-12-15 08:10 You have to open the fieldlist editor of the your dbf component (select your component, click right mouse and select edit fields). Use + button to put all your fields into it (component must be active). Select the field you want to change. Go to the readonly property and set it to true. I just test it with the DBGrid and it works at it should be. My readonly column can't be edited (Lazarus 1.42 / FPC 2.64 Windows 10) ---------------------------------------------------------------------- Hopestation · 2015-12-15 18:52 Thanks again, mangakissa. I had no idea you could do that. I tried it and I can see what you mean. Where do I find more detailed information on the operation on Tdbf? ---------------------------------------------------------------------- mangakissa · 2015-12-16 08:04 http://wiki.freepascal.org/Lazarus_Tdbf_Tutorial ---------------------------------------------------------------------- Hopestation · 2015-12-16 13:43 Thanks. I said in my 2nd message that I have read that. I created a database, including Boolean fields, using their example, but this is only a tutorial not the definitive guide to everything DBF. It didn't cover how to open the datafield explorer that you described. Where do I find this information? ---------------------------------------------------------------------- mangakissa · 2015-12-17 08:30 It's Delphi related, but works the same: http://docwiki.embarcadero.com/RADStudio/Seattle/en/Creating_Persisten t_Fields http://etutorials.org/Programming/mastering+delphi+7/Part+III+Delphi+D atabase-Oriented+Architectures/Chapter+13+Delphi+s+Database+Architectu re/The+Fields+of+a+Dataset/ ---------------------------------------------------------------------- Hopestation · 2015-12-17 10:37 Thanks again. This is a brilliant site. I have found details on how TDBGrids work, but not how the ReadOnly property applies to individual coulmns. I am sure further searches will find what I am looking for. The only remaining question is my original one. You and madref have both given me workarounds, but nobody has explained why I can't set individual columns to ReadOnly and the rest to not ReadOnly. I will have to assume that this is a bug and leave it at that. Thanks again. ---------------------------------------------------------------------- mangakissa · 2015-12-18 09:13 No, not a bug. In TDBGrid you have a columns property. Clicking on it will give you a column editor were you can create columns for TDBGrid. Each column has his own properties.