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!

Multi select in Grid

Status
Not open for further replies.

NewBieDJ

Programmer
Feb 23, 2006
8
US
I am using FoxPro 8 in XP. I was wondering if we can select multiple rows of a grid column using the shift key. I have a combo box in one column of a grid. I want to fill several rows at a time with the selected combo item. How can I select multiple rows of a column? It should be just like how we select multiple controls at a time in a form to change the font style or size etc.

Can any body please give me a hint or sources where I can look in to?

Thanks in advance.
 
This is not working properly for me. I don't understand where I am making mistakes. I have changed the code according to my necessity. Please look at it and let me know where I am wrong.

I am using a grid in a form and my 2nd column of a grid is a combo box. I want to select the few rows of a 2nd column(cells) using shift + mouse and change all the selected cells with one of the itmes in the combo box. But for some reason it doesn't seem to work. The first cell in the 2nd column gets selected when I click it first and when I click the 2nd cell in that column nothing seems to happen. When I debugged it I found out that it runs to the last record of the table. I don't understand why it is happening. I have made the chages to the form according to FaQ184-433.

LOCAL lcSelected, lcMarked

lcSelected = THISFORM.cAlias + [.Selected]
lcMarked = THISFORM.cAlias + [.Marked]

IF TYPE([&lcSelected]) = [L] AND TYPE([&lcMarked]) = [L]

#DEFINE VK_lSHIFT 0x10
#DEFINE VK_lCONTROL 0x11

DECLARE INTEGER GetKeyState IN WIN32API INTEGER

DO CASE
CASE GetKeyState(VK_lSHIFT) != 0
REPL (lcSelected) WITH .T.
WITH THIS
IF .lShiftClick AND !&lcMarked
REPL (lcMarked) WITH .T.
LOCATE FOR &lcMarked
SKIP
.lShiftClick = .F.
ELSE
THISFORM.nRecNo = RECNO(THISFORM.cAlias)
REPL (lcMarked) WITH .F. FOR &lcMarked
GOTO THISFORM.nRecNo
REPL (lcMarked) WITH .T.
REPL (lcSelected) WITH .T.
.lShiftClick = .T.
ENDIF
ENDWITH
CASE GetKeyState(VK_lCONTROL) < 0
REPL (lcSelected) WITH .T.
WITH THIS
.lShiftClick = .F.
ENDW
OTHE
.lShiftClick = .F.
ENDCASE
ELSE
WITH THIS
.lShiftClick = .F.
ENDWITH
ENDIF


Can some one please tell me what's going on here?

Thanks

 
NewBieDJ

NewBieDJ said:
I am using a grid in a form and my 2nd column of a grid is a combo box. I want to select the few rows of a 2nd column(cells) using shift + mouse and change all the selected cells with one of the itmes in the combo box.
I'm afraid I don't understand that statement.

By enabling multiselection in your grid,
FAQ184-433 said:
You now have a scope clause available for copying, printing, deleting etc, expressed as REPORT FORM reportname.frx FOR TABLENAME.selected...
To replace the field values in the .RecordSource table of the grid with one of the items of the combobox, you could use code such as
Code:
[COLOR=blue]REPL TABLENAME.fieldname WITH THISFORM.cboMyCombo.Value FOR TABLENAME.selected IN TABLENAME[/color]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.net
PDFcommandertm.com
 
What I am saying is I have a grid and its 1st column has a text box and the 2nd column has a combo box and the 3rd column has a text box etc. in the grid. And I want to have a multi select on a column which has a combo box as a current control. But in this coding what I have found out is the value of GetKeyState(VK_lSHIFT) is different every time I hold the shift key down. And also I am not able to select the corresponding rows in a .RecordSource table of a grid whenever I move to the next row of the grid.

thisform.grid1.AfterRowColumnChange
LPARAMETERS nColIndex

THISFORM.nRecNo = RECNO(THISFORM.cAlias)
THIS.Refresh()


The Thisform.nRecNo is always 1 even when I move to the next record in the grid.

Why is this happening?
 


Grid1.AfterRowColChange()
THISFORM.nRecNo = RECNO(THISFORM.cAlias)
THISFORM.REFRESH()

What I mean to say is the value of "THISFORM.nRecNo" is always "1" no matter which row I select with "Shift + left mouse button" down.

I thought this was going to change whenever I move to different rows in a grid!!!!!

Can some one please tell me why is this value not getting changed? or how will I get the current row number during run time?
 
NewBieDJ

Thanks for the further explanation.

Whilst it's possible to use a combobox in a grid, IMHO, it should only be done as a last resort.

What I would suggest is that you reconsider the design of this form and remove the column in the grid containing the combobox.

Then add a second grid or listbox. In the .AfterRowColChange() event of the grid call a form method that would populate the grid or listbox.

Thus you have two sets of data that are visible at all times.

Then you can implement
NewBieDJ said:
I want to fill several rows at a time with the selected combo item

The code you posted is an edited version of the form method .mSelectRecords(), with half the code missing.

If you examine it closely you can see what code you have omitted that assigns values to THISFORM.nRecNo.

If you are going to make the changes suggested, it would be better if you were to abandon this thread, make the changes and then start a new thread detailing your new situation.

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.net
PDFcommandertm.com
 

Chris,

I cannot change the combo box as it is done that way earlier in the project where I do not have the choice to re select the contros on the form.

The 2nd thing is I don't know why you are saying that THISFORM.nRecNo is not getting assigned. It does get assigned in the grid1.AfterRowColChange and also in the form.mSelectRecords() as THISFORM.nRecNo = RECNO(THISFORM.cAlias). The only thing is I am not able to get the corresponding row numbers when I move up & down in the grid. If I can get that then probably I can assign that number to the .nRecNo. How do I get the changed row numbers whenever I make a move in the grid?
 
NewBieDJ

If you can't implement the suggested changes, so be it.

What I would suggest is that you create a new test form outside your application with the layout previously suggested, utilise the code in the FAQ and ensure that the grid works correctly in that you can select multiple records.

Then progress to utilising the second grid/listbox to facilitate
NewBieDJ said:
I want to fill several rows at a time with the selected combo item.
Once you have that working as well, you can then work on how you can use the embedded combobox in the grid.

You also say you are using
NewBieDJ said:
Shift + right mouse button
The purpose of FAQ184-433 is to show how you can emulate Windows Explorer behaviour in a VFP grid. Shift + right mouse will bring up a shortcut menu in Windows Explorer so unless you have a good reason for doing so, I suggest you stick with normal Windows Explorer behaviour and use Shift + left click.

There is no code in the FAQ that accomodates Shift + right mouse, so you would have to add the relevant constant and amend the code accordingly.

Posting edited code snippits out of context can be confusing and does not help members in their quest to help you.

Suggest you take some time to learn how to post code, correctly indented for preference, by clicking on the Emoticons/Smileys link and also take a look at the FAQ in my signature block.

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.net
PDFcommandertm.com
 
Apologies
Chris said:
Shift + right mouse will bring up a shortcut menu in Windows Explorer
should be
Chris said:
Shift + right mouse will select multiple files and also bring up a shortcut menu in Windows Explorer

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.net
PDFcommandertm.com
 
Chris,

Thanks for being so helpful. The idea of posting edited code snippits out of context was to make sure that the changes that I have made is not the reason for not getting the required result. And also I was using shift & the left mouse. Sorry for not giving the correct information. As you said I was doing all these on a separate form with a new grid with a combo box in it. I know the posted code in the FAQ should definitely work with without the combo. But I needed it with the combo box in it. So I was asking for a help and trying to clear your doubts. Sorry for confusing you all along.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top