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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

It is possible to click on a grid column cell and store that value to run a report based on it 1

Status
Not open for further replies.

titoneon

MIS
Dec 11, 2009
335
US
Hi Experts,

can i select from a grid column, in my case the column is "purno", the "cell value" of a particular record and then store this value in variable in order to open another form or run a report, to display more information related with that purchase order number ?

in other words, i would like to either double click or click the value in cell located under the column "purno" and then once we picked the vaue of that cell, then run a report to display more data related to that purno, that was not included in that grid record cause otherwise the grid will be to long to scroll horizontally ?

i need to be able to click or double click, from the Grid under the "purno" column a value and run a report using that value as the key to find the rest of the data related with it.

can you please suggest ?
Here is the code i have to create the grid, by the way the grid was just created by dropping the Grid control in the form, so i use the code below to fill the grid with data, so i don't know how to accomplish what i am asking.
can you please suggest ?
Thanks in advance

Code:
thisform.label5.VISIBLE=.t.
thisform.label5.Enabled=.t.	
thisform.Refresh()
doevents
PUBLIC lcJob_no  

SET EXCLUSIVE OFF
SET SAFETY OFF
SET CPDIALOG OFF
lcjob_no= thisform.txtTextBox.Value
thisform.label5.VISIBLE=.t.
thisform.label5.Enabled=.t.
path_1="S:\PRO50\APEX04\POTRAN04"  &&VFP 5.0 TABLE TYPE
path_2="F:\MFG\ENG_JOBS"           && FOXPRO DOS 2.0 TABLE        
path_3="F:\MFG\INS_LOG"            &&  FOXPRO DOS 2.0 TABLE
path_4 ="s:\pro50\apex04\apvend04" &&VFP 5.0 TABLE TYPE

Select INT(VAL(t1.dept)) as ball_no, sht as Sheet, INT(t1.QtyOrd) as QTYORD, INT(t1.Qtyrec) as QTYREC, t4.company as VendorName, t2.part_type as  PRC, t2.draw_no, t1.item as ItemNo, t1.vpartno as vendorpartno, ;
t1.descrip, t1.Recdate, t1.purno;
 From  (path_1) t1 ; 		 
	INNER Join (path_2) t2;
	ON INT(VAL(t2.ball_no)) = INT(VAL(t1.dept));
	INNER JOIN (path_4) t4;
	ON t1.vendno = t4.vendno;
	 WHERE  t1.reqno= lcJob_no AND t2.job_no=lcJob_no ; 
		ORDER BY 1,2,8 INTO Cursor RESULS1 readwrite

Local lnValue, lcSuffix, lcSheet

Scan
     lnValue = ball_No
     lcSuffix =  Iif(Between(Asc(Right(Alltrim(draw_no),1)),48,57),'',Right(Alltrim(draw_no),1))
     Do Case
         Case Between(m.lnValue,1,999)
             lcSheet = substr(ALLTRIM(Transform(m.lnValue,"9999999")),1,1)+m.lcSuffix

* Since converting character to integer will loose zeroes on
* the > left, then override those that are less than 200
             If m.lnValue < 200
                 lcSheet = '1'+m.lcSuffix
             Endif
         Case Between(m.lnValue,8000,8999)
             lcSheet = ''
         Case Between(m.lnValue,7000,7999)
             lcSheet = '7'+m.lcSuffix
         Case Between(m.lnValue,9000,9999)
             lcSheet = '9'+m.lcSuffix
         Otherwise
             
 lcSheet = substr(ALLTRIM(Transform(m.lnValue,"9999999")),2,1)+m.lcSuffix

     Endcase

     Replace sheet With m.lcSheet
 ENDSCAN
 GO top

Select ball_no, Sheet, QTYORD, QTYREC, VendorName, PRC, ItemNo, vendorpartno, ;
descrip, Recdate, purno;
 From  RESULS1	ORDER BY 1 INTO Cursor RESULS2 readwrite	
 
thisform.label5.VISIBLE=.f.
thisform.label5.Enabled=.f.		

If _Tally > 0
	With Thisform.grid2
		.Visible = .T.
		.ColumnCount = -1 
		.RecordSource = 'resuls2'		
		.Refresh()		
		.Setall("DynamicBackColor", "IIF(resuls2.qtyord = resuls2.qtyrec, RGB(255,255, 0), 0xFFFFFF)") &&255, 255, 0 yellow	
		.Column3.DynamicForeColor=  "IIF(resuls2.qtyord= resuls2.qtyrec, RGB(255,0,0),RGB(0,0,0))" 
		.Column4.DynamicForeColor=  "IIF(resuls2.qtyord= resuls2.qtyrec, RGB(255,0,0),RGB(0,0,0))" 
	ENDWITH
	 thisform.buttonx1.Visible = .t.
	 Thisform.buttonx1.Enabled =.T.
	 Thisform.Sstoexcel21.Enabled=.T.	 
	 Thisform.command4.Enabled=.T.
	 Thisform.command2.Enabled=.T.
	 thisform.command1.Enabled= .F.
	 thisform.label3.Enabled=.T.
	 thisform.label3.VISIBLE=.T.
	 Thisform.Text1.visible=.T.       
	 thisform.label7.VISIBLE=.t.  
	 
Else
	Messagebox('There is not result for your Query, Check again your Entry',0+64,'Ok!')
	thisform.command1.Enabled= .F. 	
	Thisform.command4.enabled=.F.
	Thisform.command2.enabled=.t.
	thisform.label3.Enabled=.f.
    thisform.label3.VISIBLE=.f.
	thisform.buttonx1.Visible = .f.
	Thisform.buttonx1.Enabled =.f.
	Thisform.TxtTextBox.Value=''
	thisform.label7.VISIBLE=.f.
	Thisform.Text1.visible=.F.
   	
	Thisform.TxtTextBox.SetFocus
	With Thisform.grid2
		.Visible = .F.
		.ColumnCount = -1
		.RecordSource = '' 
	Endwith
Endif
 
Hi Ernesto,

Yes, this should be fairly straightforward.

First, I would advise that you use a double-click rather than a single-click to trigger the desired action. It will be too easy for a user to accidentally single-click in the cell in question, and therefore trigger the form or report without meaning to. A double-click takes more of a conscious effort.

In order to determine the value in the cell, you simply look at the value in the corresponding field in the underlying cursor, that is, the Purno field. You do that in the column's DblClick event. Store the value in a variable or a property of the form.

Next, you need to get the "more data" that you want to display in the report. I'm not sure what data you want to display, but presumably you will do a SELECT, using the value from the cell as part of the filter condition (that is, the WHERE clause). You send the result of that SELECT to a new cursor.

Finally, you run the report, using the data from the new cursor.

Does that answer your question, or have I misunderstood?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello Mike,
You understood correctly, but i am not sure if i understood correctly.
So you are telling me to go to the grid columns's double click event and type this line of code, for example right in there
"lc_value = purno" , is that what you meant(sorry if i misunderstood) ?

then use the lc_value in my select sql as for below

SELECT * FROM TABLE WHERE PURNO=m.lc_value into cursor junk nofilter

what i always thought was, since my Grid it is just a control dropped in the form and this one does not have under the grid properties header, columns text,etc.., that i needed to add code as for example as the one below in my code

Code:
Procedure grid.column11.Text1.DblClick  && where column11 is the where the purno is in the grid
            lc_value = purno
            SELECT * FROM TABLE WHERE PURNO=m.lc_value into cursor junk nofilter 
 Endproc

Then later call my report using the obtained data in cursor junk.
Please clarify me, if i should do it, as you told me (which mean i understood your point) or if the above code is corret or incorrect
Thanks a lot
 
Yes, that's pretty well what I had in mind. The cursor (junk) will contain all the data from all the records whose Purno is the one that was double-clicked. If use that cursor to drive the report, you should get exactly what you want.

Give it a try and see if it works.

The only very samll change I would make is to call the cursor something other than junk, since it clearly does not contain junk. But that's not really relevant to the solution.

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top