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

Highlight Selected Item

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi,

In a search form of Sales Invoice following are the options:

Search through
1. Customer Code (pcode)
2. Item Code (icode)
3. Rate
..
.. etc

Is it possible to change the forecolor of the selected items in Grid as well as on form when it displays.

Thanks

Saif

 
What do you mean with "as well as on form". The grid is on the form, isn't it?
Since I think VFP8 we have some Hightlight Properties in the grid class, take a look at these: HighlightRow, HighlightStyle. I would recommend HighlightRow = .t. and HighlightStyle=2.

Bye, Olaf.
 
Thanks for the reply!

I mean the selection outside the grid.

Thanks

Saif
 
Saif,

Your question is not clear to me either. You said you want to highlight "the selected items in Grid", but then you said "I mean the selection outside the grid." Which is it?

In general, you can highlight any item in a textbox or a label by changing its ForeColor and BackColor properties. To highlight a row within a grid, do what Olaf said. To highlight a cell within a grid (a single item), change the ForeColor and BackColor of the contained textbox.

Does that help at all?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
In general the focused control will have a highlight, a slim border around it, less visible sometimes, depends on theme settings. To strengthen this effect setting the background color would be a good way, indeed. Do so in GotFocus and unset it in LostFocus.

GotFocus Event:
This.Backcolor = RGB(...) && whatever you like

LostFocus Event:
This.ResetToDefault("Backcolor")

Bye, Olaf.
 
Thanks for the reply!

In a data entry of Sales Invoice, if a user search records of a customer through Customer Code, Data, Item Code and whatever the results he/she gets, it should distinguish in Red Color so that he/she can understand that options selected.

Customer Code, date, locations and other customer related information are in a container on a form. And, the grid display Item Code,Quantity, Rate and Amount etc. So, if a user search through Item Code it should display Item Code in red in grid and similarly Customer Code, date etc should display in red if it is selected for search in container.

Thanks

Saif
 
So you want to know how to change the selected item color of a listbox? Or what control do you use for searching? You only talked of "the form", but the form does not dispaly anything, you have further controls on your form showing data, each control has it's own ways and properties for it's visual styles.

The grid will display whatever current record highlighted, there is no selection of records in a grid. With HighlightStyle=2 the grid will do the highlighting with persistence, meaning, not only when it has focus, but also if the focus is somewhere else on the form. So the grid should hightlight the record you find by a SEEK or LOCATE anyway.

The color of the listbox selected item(s) determined by Listbox.SelectedItemForecolor and Listbox.SelectedItemBackcolor.

Bye, Olaf.

 
Saif,

So the row you want to highlight in the grid is not necessarily the currently selected row?

If that's right, you can do it by using the DynamicForeColor and DynamicBackColor properties of the column that you want to highlight (customer code in your example). I won't try to explain the details here because I am still not certain it is what you want. But, if it is what you want, this article will explain what to do.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Mike

The row you want to highlight in the grid is not necessarily the currently selected row?

Yes, I don't want the current row to be highlighted only the result of the searched records.
Let me think how can I elaborate more to explain.

Thanks

Saif
 
1. Customer Code (pcode)
2. Item Code (icode)
3. Rate

Are these choices for what to search also the columns of the grid, perhaps?

You might make it easier to comprehend your question, when adding a screenshot. You have the option to add an inmage in your message, here. You just have to upload it somewhere (eg your homepage, google drive public folder, dropbox public folder...) so you have a URL you can specify here.

Bye, Olaf.
 
One thing you can do, for examples is having the following:

1. a grid with your data (columns pcode,icode,rate)
2. a listbox to select what column to search in.
3. a textbox for entering the search text (or number), what to search for

Now, when the user selects the column to search in by selecting an item in the listbox (2) you can highlight the grid column using the dynamicbackcolor of that column, eg when via a case:
Code:
* listbox interactivechange
do case
   case this.value = "pcode"
      for each loColumn in Thisform.grid.Columns
         loColum.ResetToDefault("DynamicBackcolor")
      endfor
      Thisform.grid1.Column1.DynamicBackColor = RGB(240,240,0)
   case this.value = "icode"
      *...
   case this.value = "rate"
      *...
   otherwise
    *...
enddo

Now when the user enters a search text, you set the DanymicForeColor of the same column to an IIF resulting in red for matches and black for non matches, eg
Code:
Textbox interactive change
do case
   case Thisform.Listbox1.value = "pcode"
      for each loColumn in Thisform.grid.Columns
         loColum.ResetToDefault("DynamicForeColor")
      endfor
      Thisform.grid1.Column1.DynamicForeColor = "IIF(["+This.Value+"] $ pcode, RGB(255,0,0), RGB(0,0,0))"
   case Thisform.Listbox1.value = "icode"
      *...
   case Thisform.Listbox1.value = "rate"
      *...
   otherwise
    *...
enddo

Bye, Olaf.
 
2 errors:

1. Thisform.grid1.Column1.DynamicBackColor = RGB(240,240,0) should be
Thisform.grid1.Column1.DynamicBackColor = "RGB(240,240,0)"
2. Make "Textbox interactive change" a comment, or don't copy it at all, it's merely telling where to put that code, anyway.

Bye, Olaf.
 
Also:

You can put the FOR EACH loops before the DO CASE in both methods and a DO CASE ends with ENDCASE, not with ENDDO.
The compiler will tell you more errors :)

Bye, Olaf.

 
I am not sure your real question. If you want to high ligh the selected or meeting the seacrh criteria. Youe have few choices.
1. Create a temporary cursor and set that cursor as a source for the grid on the form.
2. Add a new fields call it SELECTED of type datetime. Then when the user hits the Enter key to search - assign to a variable the current data and time. Update the field SELECTED with CurrentDateAndTime variable all records meeting the criteria. Now you have to use Olaf's approach to update the row ForeColor or BackColor or Both. And do this for all visible columns.

Use the following statements (or similar idea) at places

Code:
cx_CurrentSet = DateTime()
* Assuming PCODE is field name and txt_PCode is the TextBox on the form where user enters the search string.
* Check for txt_PCode is not empty.
replace all SELECTED with cx_CurrentSet for at(alltrim(thisform.txt_PCode.value)) > 0   
Thisform.grid1.Column1.DynamicBackColor = "IIF(SELECTED=cx_CurrentSet,RGB(240,100,100),RGB(240,240,240))"

nasib

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top