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

Grid

Status
Not open for further replies.

jawadfrhad

Programmer
Sep 4, 2017
25
IQ

Hello everyone
He has a question that was asked on more than one site, and I did not find any answer to it, and the answers were far from my question, so I will ask it here...

I want to search for a letter in a group of words and I want all words that start with this letter or in the middle or at the end of these words to appear..and this is done inside the grid.
I mean be in
thisform. column. text
I hope someone answers with this and reinforces it with an example to benefit you...
greetings to you all
 
This is certainly possible. Let's break the problem into two parts.

First, the searching. I'll assume that your word list (the one you are searching) is stored in a table. If so, you can search it like this:
[tt]
SELECT Word FROM WordList WHERE AT(Word, cLetter) > 0 INTO CURSOR csrFound[/tt]

where WordList is the table, Word is the field in the table, and cLetter contains the required letter.

That will give you a cursor containing the found words.

The second step is to display the contents of the cursor in a grid.

I'll assume you already know how to place a grid on a form. Having done that, you set its RecordSourceType property to 1, and its RecordSource property to the name of the cursor (csrFound in my example). You need to do that after the cursor has been created. So put the above SELECT command in the grid's Init, followed by code to set the two properties.

There are a few other points to keep in mind, such as dealing with case sensitivity, but the above should get you started.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
And if the word list that you are searching is in an array, you just need to copy it to a cursor first:

Code:
CREATE CURSOR csrFound (Word C(18))
FOR lnI = 1 TO ALEN(laWords, 1)  
  && assuming laWords is the array containing the words to be searched
  INSERT INTO csrFound (Word) VALUES (laWords(lnI))
ENDFOR

then proceed as above.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks for your response Mike.
Great problem analysis.
But I think there is something my friend did not know.
I would like to send you a picture showing what I want and thank you again.
Can you send me an example as in the picture and I will be grateful to you
Untitled_qe6uqq.jpg
 
The problem is that I write the code you sent me inside thisform.column2.text1
And you tell me to make
The RecordSourceType property is 1, and the RecordSource property ..
This RecordSourceType does not exist inside text1
I'm sorry and I apologize if you didn't understand me earlier and now..
Could you upload your (form.scx and form.sct) so that I can show you what I want?
I wish you success
 
I write the code you sent me inside thisform.column2.text1

No, you shouldn't put your code there. As I said earlier, you should put the code in the Init of the grid. It's the grid that has the RecordSource and RecordSourceType properties, not a textbox or a column.

In fact, you will probably want to go further. Putting the code in the grid's Init means that you will only be doing the search once, when the form is first opened. In practice, you probably want some way of prompting the user for the letter to be searched. If so, you will need perhaps a textbox on the form (not in the grid) where the user enters the required letter, and a button to actually do the search. The code that I showed you would then go in the Click event of that button.

Could you upload your (form.scx and form.sct) so that I can show you what I want?

No, I can't do that. I haven't got a form that shows what you want. It's up to you to create your own form. I'm happy to make general suggestions for solving the problem, but I'm not going to actually create the form for you.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you and thank you for your patience..
I will seek to find someone who solves my problem
 
Hello,

maybe, if understand the picture, you want toenter values in a grid (i never do that) coming from another table having a letter..
You may place a combobox into the grid, deleting the usual textbox which is there by default.
You will need code to fill the combobox according to user input.

If this correct ?
Then we may help on filling the combobox interactively (I myself never did that)

Or may be a class with a textbox for input and a grid showing the matches) instaed of a combobox.
We created that for a textbox which only allows entry from another table

Regards
tom

 
Yes, it is. But I did it and it works for me correctly. The problem with it is that it only searches for the first letter.
And if you want to download the form .. I will download it
 
jawadfrahd said:
The problem with it is that it only searches for the first letter.

Well, how do you search?

Mike told you how to locate data with the entered letter (or multiple entered letters) by using AT(fieldname, cEnteredLetters)

So if you LOCATE FOR fieldname=cEnteredLetters you have to change that to LOCATE FOR AT(fieldname, cEnteredLetters)>0
This will locate on the first record containing the entered letters.

You can then also find all records matching by iterating while records are FOUND() with CONTINUE.

In short, show what you already have, and we can try to improve it.


Chriss
 
hi Chris Miller
Now I have downloaded the form, and when I run the form and write the letter j inside the grid, a bar will appear with a value of jawad.
Which I want when I type the letter j the results show jawad and moj.
Thank you
 
 https://files.engineering.com/getfile.aspx?folder=7c0ee740-7427-4989-91ae-4da696e56f40&file=serch_grid.rar
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top