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

how to populate grid? 2

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
0
16
PH
Hi everyone... i have designed a form in a form designer... as shown in the picture...
heto_k33r3h.png


with recordsource sms2
and the recordsource type is 1 - alias
grid name is Grdsms2
and code in the interactive combo1

sele sname, fname, grade, special from sms2 where grade == upper(alltrim(thisform.combo1.value))

my intention is show only the grade chosen in the combobox...

But in the current grid it shows all records in the table sms2.

Please help me how to show only the grade chosen in the combobox.... Thanks....
 
Mandy,

The problem is that your RecordSource is sms2, which means the entire table will be shown in the grid (as you can see). You are then selecting a subset of the table. That's what your SELECT statement does. But that doesn't change the RecordSource, and so won't affect what you see in the grid.

Instead, do it this way:

1. In the grid's Init, create a cursor that contains all the records.

2. Set the RecordSource to the name of that cursor.

3 In the combo's InteractiveChange, remove the ReocrdSource, then do your SELECT, but send the results to the cursor (the same one as in step 1, above), then re-instate the RecordSource.

4. Refresh the grid.

In other words:

Code:
* Grid's init
SELECT sname, fname, grade, special FROM sms INTO CURSOR csrSMS
THIS.RecordSource = "csrSMS"
THIS.RecordSourceType = 1
etc.

* Interactive change of combo box
THIS.RecordSource = ""
SELECT sname, fname, grade, special from sms2 ;
  WHERE grade == upper(alltrim(this.value)) ;
  INTO CURSOR csrSMS
THIS.RecordSource = "csrSMS"

THISFORM.MyGrid.Refresh

A simpler way of doing it would be simply to SET FILTER to the required setting, but that is generally considered not best practice, mainly because SET FILTER on a large table can make the grid very slow. But you might like to try it.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike it worked... but i can no longer click the MARK column in chosing... before i can choose multiple record... is it because that i am using a cursor, if so, how would i click or multiple record just like when it was set to directly to table? Because i want to choose from the records by clicking the check at the right, Ive set the field to logical.... Thanks...
 
What do you mean by the MARK column? Do you mean the column at the very left of the grid that indicates the current row? And how were you previously choosing multiple records? That's not something that a grid normally allows.

In general, using a cursor rather than a physical table shouldn't prevent you from clicking any particular column. The main point to keep in mind is that, with a cursor, if you make any edits to the data in the grid, those edits won't automatically be transferred back to the physical table. You would have to write code to explicitly do that.

Also, when you create a cursor with SELECT (as is the case here), the cursor is by default read-only, which means that you won't be able to edit the grid at all. Perhaps that's the root of your problem. If so, you can get round that by adding READWRITE to the SELECT statement. But my above point about the edits not being transferred to the table will still apply.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Oh I see Mike.... I am actually putting a check mark in the checkbox in the MARK column i am choosing record Mike... i dont how to explain it well Mike im sorry... but in the grid i want to choose record by clicking the check box in the MARK column.... so it will have a value of .t. in my table....
 
Oh, I see. I should have looked at your screenshot. So, the reason that you can't do that is that the cursor is read-only. If you add a READWRITE to the SELECT, as per my previous post, it should work.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
It indeed worked Mike!!!! Thanks...

In my exit button, i have these codes...

Code:
 UPDATE sms2 SET status = thisform.grdsms2.check1.value WHERE idnum == csrsms.idnum
thisform.Release

but it tells me Alias 'Check1' is not found...

When check1 is inside column 4 of the grid named grdsms2

May you please tell me where the error? Thanks
 
Thank Mike!!! It worked again....thank you for being so kind always giving me right anwers..;
Ok mYearwood i'll try to edit my code... Thank you also for all you kindness and your substantial suggestions...

God bless everyone...
 
myearwood said:
It is a wrong user interface to let the user checkbox 1 record in a grid. The checkboxes imply you can select 1 or more.

I don't completely agree with that. It's true that checkboxes imply a multiple selection, but there might well be cases where that's what you want. You might want to select multiple items for including in a report; or a subset of records to pass to another form for processing in some way.

I don't know whether that applies in Mandy's case, but there is no reason to rule out checkboxes in a grid.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike... i am actually selecting multiple records for later processing.... unfortunately i can't seem to update all that i have check... only one at a time... I have tried these codes...

Code:
 v_special = thisform.grdsms2.column4.check1.value

UPDATE sms SET special = v_special WHERE idnum = CsrSms.idnum

thisform.Release

when i try using scan, i can't seem to have the wanted results that all that i have click in the Mark column will have .T.

Code:
 v_special = thisform.grdsms2.column4.check1.value

SCAN FOR UPPER(ALLTRIM(grade)) = thisform.combo1.Value

	IF ALLTRIM(TRANSFORM(special)) <> ALLTRIM(TRANSFORM(v_special))
		replace special WITH v_special
	ENDIF 
	
ENDSCAN

thisform.Release

Sorry Mike I'm trying my best to come with the right code... I really can't.... please help... Thanks
 
Hi Mike and Myearwood

I think i found the solution with these codes i wrote... i don't if this is correct but i have gotten the intended results...
Code:
 SELECT * FROM CsrSms INTO CURSOR Ticked

SELECT Ticked
GO TOP 

DO WHILE !EOF()

	pointer = Ticked.idnum

	SELECT tsulat
		GO top
		LOCATE FOR idnum == pointer
			IF FOUND()
				UPDATE tsulat SET special = Ticked.special WHERE idnum == pointer
			ELSE
				SKIP
			ENDIF
	SELECT Ticked
	SKIP IN Ticked
	
ENDDO 

thisform.Release
 
Yes Myearwood that field special is what i call Mark in my grid.... and yes there are multiple records in tsulat but all idnum are unique.... ok myearwood I got it! Thanks so much for answering always... God bless....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top