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!

I would like to highlight these two columns in a grid for a condtion and also see below please

Status
Not open for further replies.

titoneon

MIS
Dec 11, 2009
335
US
Hi all,
I have this grid as you can see, in the below code and besides that i am highlighting the whole record for the condition exposed in the code, also would like to highlight two columns, those are QTYORD AND QTYREC.

also wouldl like to know if can select the column ItemNo and be able to open a txtbox there to search for an specific value under that column and refresh the grif and move to that record in the grid ?

I know i am asking two question in one, please help, as you can Thanks in advance.


Code:
Select ball_no, Sheet, QTYORD, QTYREC, PRC, ItemNo, vendorpartno, ;
descrip, Recdate, purno;
 From  RESULS1	ORDER BY 1 INTO Cursor RESULS2 	
 
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)") && 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

are these two lines correct to obtain what i was asking about coloring the two columns if the condition is true ?
.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))"
Thanks
 
It looks OK to me. What happens when you run it? Are you getting an error, or what?

Off-hand, the only reason I can think of for it not to work is if the cursor no longer exists at the point at which you are refreshing the grid.

Regarding your second question, you want to capture an item number when the user clicks somewhere (on the grid, or in the column, or the column header). Is that right? If so, just put some code in the relevant Click (or DblClick, if you prefer) event. The code will open a form where the user can enter the item number in question. Or, to make it easier, you can use INPUTBOX() to capture the number.

Once you know the number, do a LOCATE on your cursor to find the relevant record. Then simply SetFocus to the grid.

Does that answer your questions? If I have misunderstood what you are asking, perhaps you can clarify.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,
Thanks for getting back to me

Regarding your second question, you want to capture an item number when the user clicks somewhere (on the grid, or in the column, or the column header). Is that right?

I would like the user to click on the column header, then be presented by a txtbox and then be able to enter the value to be searched and once have finished typing the value, then search that record and show in the grid, without pressing any other button to actually do the search

If so, just put some code in the relevant Click (or DblClick, if you prefer) event. The code will open a form where the user can enter the item number in question. Or, to make it easier, you can use INPUTBOX() to capture the number.

this part right here is the one i don't know ?

Once you know the number, do a LOCATE on your cursor to find the relevant record.
so the code to locate should be in the txtbox interactive event ?

Then simply SetFocus to the grid.
Should i put thisform.grid2.refresh() or thisform.grid2.setfocus()

Thanks again


 
For simplicity, let's suppose you will use INPUTBOX() to capture the user's entry. So the following code can go in the Click event of the column's header (that is, in THISFORM.Grid2.Column6.Header1):

Code:
lcTarget = INPUTBOX("Item number to find?")
IF NOT EMPTY(lcTarget)
  SELECT Resuls2
  lnRec = RECNO()
  LOCATE FOR ItemNo = VAL(lcTarget)    && I'm assuming ItemNo is numeric
  IF NOT FOUND()
    GO lnRec
  ENDIF
  THISFORM.Grid2.SetFocus
ENDIF

This is all you need. Personally, I would use a dedicated form to capture the item number, rather than INPUTBOX(), but start with the above and you can always develop it further.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,
Yes, this code work and the good thing about this, as you said "you can always develop it further" so your initial code, push me to go further, thanks so much for the push, this is the way i like cause allow me to understand easy stuff and try to extend it later
Thanks again
 
Glad it was useful. I think a good next stage would to make it more generic - so that you can click on any column header, to start a search for the contents of that column. So instead of referencing a particular column or table, you would pick those up from the column's control source.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

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

Part and Inventory Search

Sponsor

Back
Top