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

allowing in a grid to use shift and ctrl key to select rows 1

Status
Not open for further replies.
Jan 20, 2007
237
US
Hi everyone,
since i am very new to this vfp, specially 9.0 sp2. here is my question.

I have a grid where i can have a bunch of records/rows, so sometimes it could be a lot of rows that need to be deleted, so i was thinking instead of select one by one to delete a row, if i can use shift and arrow down or mouse click and hilite the rows, or ctrl key and mouse click and hilite the rows and if it is possible to accomplish it ?
i know i can create a check mark column to tick and untick but i don't want to use that method, so i am wondering if we can accomplish what i mentioned aboveif so ,can anyone please guide me here ?

thanks in advance
 
Not as easy as it should be, but not impossible.

The first idea to consider is to use a listbox in place of the grid. The listbox control has a MultiSelect property, which enables exactly the behaviour you want. However, a listbox is not as efficient as a grid for working with very large tables. It also had the disadvantage that the data cannot be directly edited, as it can with a grid.

If that doesn't suit you, you might be able to achieve your goal by means of the DynamicBackColor and DynamicForeColor properties (note that these are properties of the column, not the grid). You will need a new logical field in the underlying table, and you will need to arrange for that field to be toggled when the user selects a row while Ctrl and/or Shift is pressed. The DynamicXXXColor properties would test for the setting of the logical field, and change the colours of the row accordingly.

If you need any more help with the above properties, see Conditional formatting in a Visual FoxPro grid.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,
the thing is, that i need to select first, a row with a shift+ mouse click or ctrl+mouse click, and then hilite those rows, i guess then issuing it, this should use the underlying field assigned and then make it as .T. ,then in my delete click event just delete for that field=.T.

but what i don't see is, how to bind this keys, shift, ctrl and mouse click to make those rows to get hilited.
i understand that we need to use the keypress property of the grid and define there, the key pressed but what can i use in nkeycode for combining shift+ down arrow, or shift+mouse right click, or ctrl+ mouse right click and so on, this is the part i don't see, sorry for so many question, as you said it is a little complicated specially for me.
Thanks
 
Mike,
Don't worry i believe, that i should add a checkbox and delete for ticked rows, so whatever is ticked, then delete them, will be easier, of course it is always to be able to learn other tricks
Thanks in advance.
 
Well, I agree that the checkbox approach would be much simpler. But to answer your question, I think you would need to use the MouseDown event rather than the Keypress to trap the "modifier" keys (Ctrl, Shift, Alt). But it's not that simple, because you would also have to check to see if the row was already highlighted when the user clicks in it; and, if it was, you would need to un-highlight it. It gets even more complicated when you consider they might be highlighting a range of rows, but then want to un-highlight one or more rows within that range.

So, yes, go with the checkbox approach. But consider also highlighting the row in some way when the box is checked, to give the user a strong visual indication of which rows are about to be deleted. I think you'll find this approach is acceptable to your users. They might even find it easier than the Shift / Ctrl approach.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

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

Part and Inventory Search

Sponsor

Back
Top