Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grids and recno() 1

Status
Not open for further replies.

wjs2

Programmer
Jan 3, 2001
102
US
Hi All,

I'm not sure if I am asking the right question so bear with me.

I have a form created in form designer. The form has a grid dropped on it using the form control tool bar. One of the forms command buttons has the following code to get the information into the grid columns:

* Select the Grid Table

Select Options

* Set Grid Properties

Thisform.grdSortOptions.columncount = -1
Thisform.grdSortOptions.recordsourcetype = 1
Thisform.grdSortOptions.recordsource = 'Options'

* Gray out grid rows Based on record count in the table record

Thisform.grdSortOptions.SetAll("DynamicBackColor", ;
"ThisForm.txtGridBackColor.click(Options.so_reccnt)","Column")

* Get the active row when the grid is double clicked

Thisform.grdSortOptions.SetAll("DblClick", ;
"ThisForm.txtRecordNumber.value = str(ThisForm.grdSortOptions.activerow,3,0), " + ;
"ThisForm.txtRecordNumber.dblclick()","Column")

* Show the grid filled in
Thisform.grdSortOptions.refresh()

**
** End of Code
**

Obviously, "DblClick" is not a property. The question is:
How do I get the code into the grid columns 'DblClick' event? Have tried other methods and get 'DblClick event read only'.
Or, maybe more to the point, How do I get the table's record number represented by the grid entry just double clicked? (In this case the record number will be the the row activated by the double click event.)

I still don't know if I'm asking the right question.

Thanks
WJS
 
You can get your code to it by this way"
_code="ThisForm.txtRecordNumber.value = str(ThisForm.grdSortOptions.activerow,3,0), " + ;
"ThisForm.txtRecordNumber.dblclick()"

for i=1 to thisform.grdSortOptions.columncount
thisform.grdSortOptions.columns(i).text1.dblclick=_code
endfor


The rocrod number of the table option you can get simply.
I. make new property of formset, call it rec
II: In grid.afterrowcollchange event type this code
call function :
thisformset.rec=recno("option")

Now when you will move in grid so record number will be stored in thisformset.rec
 
Hi WJS,

How do I get the code into the grid columns 'DblClick' event?

I think you need to put the code in the DblClick of the textbox rather than the column, that is, the textbox which is inside the column.

Go to the property window. In the drop-down list at the very top, scroll down until you find the Textbox1 entry within the column in question. Select that entry. Then, in the main part of the property list, find the DblClick entry, and double-click on it. You can now write your code.

How do I get the table's record number represented by the grid entry just double clicked?

Remember that, when a grid is bound to a table, the record pointer of the table moves to whichever row in the grid is selected. So, if I have understood your question right, you don't need to do anything special. Just use the table's RECNO().

Hope this helps.

Mike
Mike Lewis
Edinburgh, Scotland
 
Hi,

Thanks to both of you for your responses. Unless I missed something very elementary, this particular case is 'You can't get there from here.' I've tried everything I can think of anyway. Since I used the form designer to drop the grid on a form, and, it is not bound to a table at design time, there is no 'column1.text1.dblclick' available at design time and it is read only at run time. I could get to it if I progamatically created the form and the grid, but, alas, such is not the case.

Since it was a small table, I changed the grid to a list and got it to do what I wanted. Not exactly the way I wanted to do it, but, it works.

Thanks
WJS
 
Hi WJS

You cannot add the code of an event after constructing the Grid. The way to do is..

First define a text box class by code..
*********************************************
DEFINE CLASS oTextBox AS textbox
PROCEDURE DblClick
** whatever code you want..
ENDDEFINE
*********************************************

Use RemoveObject method to remove your existing Text1 in every column and then do an ADDOBJECT method to include the above TextBox..
Example..

SET PROCEDURE TO myClassDefinition.PRG
WITH ThisForm.GridBase1
FOR EACH oColumn IN .COLUMNS
oColumn.REMOVEOBJECT("Text1")
ENDFOR

.Column1.ADDOBJECT("Text1","oTextBox")
.Column1.ControlSource = "tTran.stt_sno"
.Column1.Header1.Caption = "Sno"
.Column1.Width = 24 * nratio

.Column2.ADDOBJECT("Text1","oItemCode")
.Column2.ControlSource = "tTran.stcode"
.Column2.Header1.Caption = "Item Code"
.Column2.Width = 90 * nratio

FOR EACH oColumn IN .COLUMNS
oColumn.Header1.FontSize = nFont
WITH oColumn.Text1
.BorderStyle = 0
.Margin = 0
.FontSize = nFont
.DisabledBackColor = .Parent.BackColor
ENDWITH
ENDFOR
.Visible = .t.

ENDWITH
SET PROCEDURE TO

** In above I use the nRatio etc. to dynamicaly resize the grids columns widths as the user resizes the forms sizes.. That is a different story. But I quickly copied one of my forms codes.. I think you can pick it up from that.

:)
ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
I think you can add code after construction.

I made it for a 5 times(I think).

You can do it in run time and in design time too.



 
Hi Ramani,

Thank you very much for that one! I have stayed away from grids in some instances where they would do the job better but couldn't find a way to manipulate them the way I wanted. This is just what I like. Sneaky. Super sneaky if you have the table structure available that is used at run time.

Thanks,
WJS
 
Hi bon011,

In my particular case, the grid was dumped on the form at design time with no table structure in back of it. At run time I assigned the table structure and then turned the grid 'lose', so to speak, to do whatever it did to construct for the table that was assigned at run time. This approach is fast and flexable in terms of programming time but does have it's limitations. When I tried to assign the dblclick event at run time, by any means I could think of, Fox would come back with 'event is read only at run time.' I read on Microsofts support pages where you could an invisible something or other on top of the grid and get it to do some things. Well, the timing was bad for me to try everything in the book to get something as simple as a double click to work. If you look closely at Ramani's code, you will see that, by passing the right information to his routines, you bould build the grid's behavior flat out, on the fly. Exactly what I needed.

Thanks,
WJS
 
Hi bon011
Are you still listening to this thread? Do you remember your post
Code:
You can get your code to it by this way"
_code="ThisForm.txtRecordNumber.value = str(ThisForm.grdSortOptions.activerow,3,0), " + ; 
    "ThisForm.txtRecordNumber.dblclick()"

for i=1 to thisform.grdSortOptions.columncount
    thisform.grdSortOptions.columns(i).text1.dblclick=_code
endfor
According to me it looks too good and useful, to be true.
Was it meant like some idea of putting value to (read only) event, or does it really works under certain circumstances?
I think that a lot of programmers would be happy being able to add code in run time this way.
Can you explain it in more details?

Thank you very much
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top