Hi there. Kind of embarrassing asking simple question when other people post such advanced requests. I am new here.
I got as far as creating a form with two grids and other controls I need. There is a Pageframe that switches between pages and I have each grid on the corresponding page. All the way I am making comparisons with dBASE stuff which I hope soon will be a thing in the past.
Anyway, when I run the form all rows in grids appear to be read only. I cannot enter any information in any columns.
I want preempt a question about the tables. I did creat a database with two tables I need, made appropriate fields and indexed them. The field names appear as the headers in the grids.
Before I posted this I searched the entire help and tried to figure out which property controls it. Grid-->column-->text.enabled is .T. UIEnabled is set to default and I do not know how to change it. What is the problem I am running in
I want to be able manually enter records in grid control at runtime or be able to modify manually again records entered programmatically. I want corresponding changes to be saved in the table. Isn't it a reasonable thing to ask How can I do it
Thank you very much.

Grids are readOnly. How do I put text in them?
gabriewo
You can get better (if not the best) help at www.universalthread.com VFP forum (I hope MS doesn't get angry with me for I'm giving you that link - should not be because it's already in the product: Tools\Task Pane and select "Community" - and MS wants you to get help anyway). You'd be surprised seeing a large community that would 'die' to help you:)
Your questions are flying really:) OK let's start with TextBox first. It has many properties but the ones you'd use often are few:
.Controlsource - If it's bound to data then this one is filled. ie: Employee.First_Name
( If you do this in code then:
.ControlSource = "Employee.First_Name"
in other words in code don't forget the quotes).
.Value - this is control's value at anytime. Yes you can write something there and read it back. However if it's bound to data and data is updated/refreshed what you've written would be overwritten. In other words:
*Desing time you fill:
ControlSource: employee.First_Name
Value = Dummy
When you run the form it grabs actual value from employee and writes it there. If instead:
*Desing time you fill:
ControlSource: nothing here, left empty
Value = Dummy
Your "Dummy" is its value till you change:) Being able to write there you can specify the datatype of a Textbox when it has no controlsource assigned. ie:
*Desing time you fill:
ControlSource: nothing here, left empty
Value: {}
Causes textbox to accept date. This is like:
@ 1,1 get m.SomeVar ...
but you don't need m.SomeVar since you have something like thisform.Text1 instead.
Grids:) I love them. Grids like to snap to a source and if you don't specify one it'd build itself with the cursor it finds first. There is something special about grids and that's hierachy. Grid-Column-Textbox (and header). If you assign controlsource at column level (or readonly, enabled ...) then those properties propagate to its textbox. In other words set them at column level. Setting at textbox level needs Bound= .f. and IMHO is an advanced management. You might go nuts easily at first.
Well why can't you enter anything. Check grid's hierachy:
Is Grid.ReadOnly = .t.
Is Column.ReadOnly .t.
Both are likely not ReadOnly if you didn't explcitly set.
Is table itself readonly
Is it a table or a cursor Select SQL cursors are readonly by default (unless you didn't include readwrite clause).
Is it a wizard generated form that put controls in disabled mode
Anyway if you have a single working form with a grid, I think you could go faster:
-Create a new form
-Set datasession to 2 && Private - you'll like that you did in future
-Right click and open dataenvironment
-Add a table (for example customer from testdata.dbc)
-RightClick on top of table you have in dataenvironment and drag it on to form surface (I prefer rightclick for the menu it shows when you drop)
-Drop and select create a grid here.
-Run the form
MyLady
"To show the idea" is precisely what I need at this point!
I will have to work with the code. At this moment it does not find the alias "myParent" so I will have to take care of it. It is very helpful.
M.D.luffy
They're newly created tables and have no rows. Well VFP doesn't automatically insert one for you. You need to do it yourself. In code you can do this:
* Grid.when
if eof(this.recordsource) && No records yet
append blank
endif
But probably you wouldn't wnat to do it that way and use a simple insert instead.
You might Set allowaddnew to .t. to enable downarrow (on last row) adding a new row.
From within browse things are easier and Ctrl+Y adds new record.
Joshua_Ethan
Anyway, AllowAddNew did not do a thing, when the table was empty. Apparently it works only after you've added at least ONE record to the table because it involves the downward arrow.
What it did when I used it on my first record, it duplicated the record # 1 and generated record # 2 as an exact copy of the first record. It did not append the table with an empty record.
Well. It is a breakthrough and I will go from here.
Many many thanks.
Ken Wilson
Thank you for a comprehensive answer. I have to break it down to manageable parts.
(1) Both grid.readOnly and column.readonly properties are at .F. which is default. I haven't touched them.
(2) Tables: I created them not with the wizard since I needed my own fields. Honestly I do not understand how the readonly property can be set either way for tables. I reviewed table designer again and could not find an opportunity to tinker with it. It does not seem to be there.
My tables are empty though. There are no records in them. In dBASE you have to append a table in a query if it is empty and then you can enter something in the fields but this is true for working out of a program only. If you have a UI like a grid it will do it for you automatically. If you try to enter something into a grid it will do the append and the textbox becomes accessible once you clicked on it.
I will change the value property into Dummy. It makes sense.
I will have to study the rest of your message a bit closer to implement it. Especially the part concerning the way you bind the source to the controls. I did drop my tables onto the form but they did not seem to stay there and they appeared in a separate container which I did not quite understand.
I have to think about it more.
Thank you very much.
JStalnaker
If it doesn't work then probably there is a parent-child relationship (my second might be pointing to it). In that case you need some more code:
----------------------------
* Grid.when
If reccount('myParent')=0
Insert into myParent (PrimaryKey) VALUES (1) && assuming PrimaryKey is integer
EndIf
If !Seek(myParent.PrimaryKey,'mySecond','ForeignKeyTag')
Insert into mySecond ('ForeignKey') values (myParent.PrimaryKey)
thisform.refresh
EndIf
-------------------------------
Code is there to only show the idea. In real life you wouldn't write such a hardcoded thing (on the long run check Grid's LinkMaster, ChildOrder, RelationalExpr properties). For the time being this works.
For primarykey it'd be a surrogate key created by 'default' of the field and I wouldn't suggest to use an integer key. GUID is the way to go IMHO. However majority use integer keys (like SQL server identity) and you might do too. If you have a natural key for sure then use it.
Who am I talking to, you already come from another xBase language. Anyway I didn't want to misguide you to think I cheer up integer keys usage personally:)
catman123
shhameed
It is surprising that the designer allows a string to be assigned to it at DESIGN time!!! I entered an odd string into the window for "text1.value" and at runtime it is nowhere to be seen. What is the meaning of it I expect it to be the value of the corresponging (nRow, nCol) cell. It has no meaning at design time in my opinion. Am I making sense
dodo.net
Amit Bhave
Is there a GLOBAL switch somewhere that is responsible for it I have no problem appending by dBASE tables though every session and I use them daily.
Melle Dorel
if eof(this.recordsource) && No records yet
append blank
endif
For some reason it does not work. I just implemented this procedure for my second grid. It is still empty. This code did not append any record. At least not the way I could see. The first row is still read only.