|
|
A (simple I suppose!) grid question .... |
|
Author |
Message |
Athan

|
Posted: Visual FoxPro General, A (simple I suppose!) grid question .... |
Top |
Hi all!
I used to work with VFP a long time ago and I have almost forgot most of it so I ll need your help here! :)
I have a table (called myTable) with 4 fields (3 of C(20) and 1 Memo- ID,Title,Location,Descr.). When I am displaying that on a grid, I do that through a new cursor called myTable_cursor. But in the cursor I added a new field because what I wanna do is to display the first 20 characters of the memo and if the user wants then to double click on the memo cell and a new window to open and view all the memo field or edit the memo.
So my problems are:
1. Whatever I put in the click event in the textbox cell in the grid (in the correct memo column) it does not respond! Any solutions here
2. I use a cursor to display my table as I said. In order to edit a record I have to use another form with different textboxes for each field etc. and thats because I do not know how I can display the table directly in a grid with only the fields I like (and not ALL the fileds! Like using SQL.) or only the records I want, so that it can be directly edited. What solution can I use here
Any advices
Thanks a lot!
Athan
Visual FoxPro1
|
|
|
|
 |
CetinBasoz

|
Posted: Visual FoxPro General, A (simple I suppose!) grid question .... |
Top |
1) I don't know a solution because I don't know how to make it a puzzle first. In other words unless you prevent it somehow it responds.
2) A grid has a recordsource property, columncount property and each column have ControlSource property as a minimum. It means that you could create a grid like:
.recordsource = "customer" .ColumnCount = 3 .Columns(1).ControlSource = "customer.Company" .Columns(2).ControlSource = "customer.Country" .Columns(3).ControlSource = "(customer.Title+'-'+customer.Contact)"
Here though customer table has many fields and in a different order (starting with cust_id), we chose only Company and Country fields as the first 2 to show in grid. 3rd column is a "calculated" column which is readonly.
This is a sample for controlling columns. For limiting the rows you have a number of options:
-Set key to -Set filter to -Use a view/cursoradapter instead -Autofiltered if source is a "child" of a relation (as in one-to-many forms)
However majority of VFP developers would say that you shouldn't edit in a grid. I wouldn't say such a thing. Grids are hard to harness but once you do there is nothing wrong you can directly edit in a grid. Till you learn it well do not edit in a grid.
|
|
|
|
 |
Athan

|
Posted: Visual FoxPro General, A (simple I suppose!) grid question .... |
Top |
HI,
thanks for your answer. As for the first part, as I said I have a table:
ID I
TITLE C(5)
DESCR M
LOCATION C(15)
where I do the following select:
SELECT id, title, IIF(LEN(descr)>20,LEFT(descr,20)+"...",descr) as temp_descr, location, descr FROM myTable INTO table myTable_cursor
descr field is a memo field and what I need to check is if it is bigger than 20 characters then just to display the first 20 chars and add 3 "." at the end else just to display all of it. Now my main problem is that VFP cannot get the CLICK event on the temp_descr cell (in the 3rd column).
Does it has to do something with the column bound control
Any ideas
|
|
|
|
 |
AndyKr

|
Posted: Visual FoxPro General, A (simple I suppose!) grid question .... |
Top |
>> SELECT id, title, IIF(LEN(descr)>20,LEFT(descr,20)+"...",descr) as temp_descr
Columns that are not directlky related to underlying columns are always read-only in a grid. This may be why your Click doesn't work on that column....
|
|
|
|
 |
CetinBasoz

|
Posted: Visual FoxPro General, A (simple I suppose!) grid question .... |
Top |
You're destroying grid components and rebuilding. Why would you ever want to create a temp table when cursors are exactly for that purpose. If you had started with an SQL rowsourcetype it'd work as you wished. Anyway here is a sample similar to 'your' way:
Public oForm oForm = Createobject('myForm') oForm.Show()
Define Class myForm As Form DataSession=2 Heigth = 400 Width = 600 Add Object myGrid As Grid With Height=400,Width=600,; recordsource = 'crsEmployee' Procedure Load Select * ; FROM (_samples+'data\employee') ; INTO Cursor crsEmployee ; readwrite Endproc Procedure Init With This.myGrid .ColumnCount = 4 WITH .Columns(1) .ControlSource = "crsEmployee.First_Name" .Header1.Caption = "First Name" ENDWITH WITH .Columns(2) .ControlSource = "crsEmployee.Last_Name" .Header1.Caption = "Last Name" ENDWITH WITH .Columns(3) .ControlSource = "crsEmployee.Birth_Date" .Header1.Caption = "Birth Date" ENDWITH WITH .Columns(4) .ControlSource = "(DISPLAYPATH(MLINE(crsEmployee.Notes,1),20))" .Header1.Caption = "Notes short" ENDWITH For ix=1 To .ColumnCount With .Columns(m.ix) .AddObject('grdTxtBox','myGridTxtBox') .CurrentControl = 'grdTxtBox' .Sparse = .F. .grdTxtBox.Visible = .T. Endwith Endfor Endwith Endproc Enddefine
Define Class myGridTxtBox As TextBox BorderStyle = 0 Procedure Click Wait Window Nowait "Click works:"+CHR(13)+: This.ControlSource+CHR(13)+; TRANSFORM(this.value) Endproc Enddefine
|
|
|
|
 |
Athan

|
Posted: Visual FoxPro General, A (simple I suppose!) grid question .... |
Top |
thanks a lot for your help my friend!!! That was really helpfull!
|
|
|
|
 |
|
|