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!

Synchronizing two grids on the same table 1

Status
Not open for further replies.

florindaniel

Programmer
Dec 4, 2009
120
RO
Hello,

I think the title is not very fortunate so here's my problem:

I have a table of documents, shown on a grid onto a form.
I want to activate a menu should the user right-click in the grid so "AllowCellSelection = .F.", Right-click event does the "do menu.mpr" and it works.

On the other hand I want to have one field (Selected) that can me checked or unchecked. If Allowcellselection is .F., I can't do that, if it's .T. I can't link menu activation with the right-click of the grid.

One solution I've tried is to have another one column narrow grid, sticked along the main document grid. This grid should contain only the "selected" field and has no scroll bars, so the visual image is like being part of the main grid. That's fine but the two grids don't synchronize (they don't show the same info at a time). I've tried to use "RelationalExpr" from the Document table to itself (Document) based on an unique ID but id doesn't work.

So, please, tell me if there's some way to synchronize the two grids or maybe you have a better idea to implement that feature.

Thank you,
Daniel
 
I am not 100% clear on your issue, but I will say that creating 2 separate grids will create a visual 'disconnect' between the contents of the 2 grids.

From what I interpret from your posting above, you want to have a SELECT field (logical checkbox) and a Document field (characters).

One of the best ways to do that would be to have a single grid and work on a Cursor (READWRITE) which contains both fields. Then you would have your single grid use that cursor as its RowSource.

Maybe someone else has a more clear understanding of what you are trying to do.

If so great.

If not, then perhaps you can state your goal a little differently to make it more clear.

Good Luck,
JRB-Bldr


 
Hi Daniel,

You wrote:

I want to activate a menu should the user right-click in the grid so "AllowCellSelection = .F.", Right-click event does the "do menu.mpr" and it works. .... if it's .T. I can't link menu activation with the right-click of the grid.

That's not completely true.

If AllowCellSelection is .F., a right-click works, but it's the right-click of the grid. The event fires no matter in which column you right-click, and also if you right-click in the empty part of the grid below the data.

If AllowCellSelection is .T., a right-click also works, but it's the right-click of the textbox that you click on. If you click in the empty part of the grid, it's the grid's right-click that fires.

In both cases, the underlying table's record number will tell you which row you clicked on, so they can both be used to fire a context menu and take some action as a result.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
A. Thank you JRB, there is indeed a visual disconnect between the two grids and that's the point of my question: how not to have that visula disconnection. I'm sure I wasn't clear enough: Document is a table, and the grid showing them has 10-15 columns (No, date, customer, value, etc...)

B. Thank you Mike, I know that thing about right-click but, provided the document grid has at least 12 columns, replicating the behaviour of "allowcellSelection=.F." + right-click event of the grid, means I should (I know no other method) "do menu.mpr" on each column's associated texbox right-click event. Maybe it can be done programatically but I have another problem because the document grid has a variable number of columns depending of the nature of the documents shown in a particular datasession.
So what I really need is some sort of "AllowCellSelection=.F." on all columns except the "selected" one, that's what I am trying to perform using two grids.

Again, thank you both for answering... I still need help :)

Thank you,
Daniel
 
"that's the point of my question: how not to have that visual disconnection"

Start by using a Single Grid instead of 2 separate Grids.

Code:
SELECT DocFileNam,;
   .F. AS Selected,;
   < and whatever other fields >;
  FROM MyData;
  INTO CURSOR GridData

Then have a single Grid where Grid.RowType = 'Alias' and Grid.RowSource = 'GridData' and use a Checkbox (instead of a textbox) to display GridData.Selected.

Then from that you can put any Valid Method code you need to operate on the 'Selected' value into the Grid objects.

Good Luck,
JRB-Bldr
 
Thank you again JRB... I'm not a native English speaker
so perhaps that's why you don't understand me. Sorry, I do my best :)

I can not have a single grid since I want to right-click in the grid, on whichever 15 columns from the 16 columns of the grid, and activate a popup (code embedded onto grid's
right-click event, because I don't want to embed that code 15 times in 15 right-click events of the text associated with the column-that's why I don't allow cell selection-).

Now, when I click on the checkbox from the 16th column of the grid, I want to check/uncheck that document (well, the field associated with it, a logical value .T./.F.)

Thank you
 
You can download public domain version of MultiSelectGrid from
That would provide a grid with multi selection of rows enabled. You are free to modify its code (the version with more capabilities and checkboxes is commercial and part of FoxyClasses)

Cetin Basoz
MS Foxpro MVP, MCP
 
Put code in the grid's Init to use BindEvent on all the textboxes so that textbox.RightClick fires grid.RightClick.

Tamar
 
Hello,

Now I'm trying Tamar's solution. Because the gris has a variable number of columns and I add columns in the Init method of the form, I also want to BindEvent in the Init of the form. Unfortunately I'm not very familiar with that and I'm trying the code below, wich doesn't work:

form's Init:
============
PUBLIC goColTxtHandler As Object
goColTxtHandler=NEWOBJECT("TextBox")

LOCAL lcCaption, lcTag As String
LOCAL loColumn As Object
FOR EACH loColumn IN ThisForm.grdDocument.Columns
lcCaption = loColumn.Header1.Caption
lcTag = loColumn.Header1.Tag
loColumn.AddObject('MyHeader1', 'MyHeader')
loColumn.MyHeader1.Caption = lcCaption
loColumn.MyHeader1.Tag = lcTag
BINDEVENT(loColumn.Text1, "RightClick", goColTxtHandler, "ThisForm.grdDocument.RightClick")
ENDFOR

Thank you
Daniel
 
Stupid me :(

It works fine with:
BINDEVENT(loColumn.Text1, "RightClick", ThisForm.grdDocument, "RightClick")

Thank you all again
Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top