We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Table-Dependent GridGroupingControl Context Menu

I want to create a context menu in a GridGroupingControl having a datasource with Relations. The actual context menu displayed needs to vary depending on whether the user right clicks on the top-level grid or in one of the nested grids. The handler also needs to be able to detect if the user clicks in other than in an actual data row or column (caption, header, etc.). Also, the context menu needs to pass a parameter to its event handler corresponding to the text value of column named "ID" of the row clicked. I''ve tried handling the TableControlCellMouseUp event and using e.TableControl.TableDescriptor.Name to get the name of the table associated with where the user clickced, but this returns the wrong table name every other time if the user clicks inside a nested grid. Also, it returns the wrong table name if a right click is done first in the top-level grid and then into a nested grid, or vice versa. I''m using with the patch. Any suggestions are appreciated. --Van Baker

6 Replies

AD Administrator Syncfusion Team October 10, 2004 07:32 PM UTC

Here is a little sample showing how you might do this. The context menu shows the type of the clicked element. 13206_6279.zip

VB vbaker October 10, 2004 09:05 PM UTC

Thanks for your reply. When I run your example, the context menu often shows the incorrect type of the r-clicked element. For example, when I run the program and then r-click on the parent Add Record row, the context menu handler incorrectly indicates this is a "Grid Record Row". Then, if I expand one of the child records and r-click on a child data row, it correctly shows as "Grid Record". However, if I then r-click on one of the child''s header cells, it (incorrectly) also shows as "Grid Record". BTW, if I expand any child grid and then immediately r-click on its "ChildID" header and select the MenuItem1 from the context menu, a null reference exception throws. This behavior seems eerily similar to what I''ve been seeing in my r-click handlers. Is it possible there is a problem with the way CurrentElement is being updated when a r-click occurs? Also, could some events be getting "missed" yet still queued and thus handled later and out of sync with the user''s actions? --Van Baker

AD Administrator Syncfusion Team October 11, 2004 07:21 AM UTC

If you move the code into TableControlCellClick instead of TableControlMouseUp, if performs better. Here is another try that has been tweaked a little. 13206_6435.zip

VB vbaker October 11, 2004 10:39 AM UTC

Thanks! That really helped a lot. The key information for me was in the two lines: tableCellStyle = e.TableControl.GetTableViewStyleInfo(row, col); contextElement = tableCellStyle.TableCellIdentity.DisplayElement; Also, I had really been searching for the method: PointToRowCol(pt, out row, out col) that works with the GridGroupingControl but didn''t know where to find it. (I guess it''s logical it was a method if e.TableControl.) One more question: In your example you display contextElement.ToString(). How do you get access to the individual column names and values, other than parsing the string? Calling contextElement.GetData() does not seem to work. --Van Baker

AD Administrator Syncfusion Team October 11, 2004 11:26 AM UTC

If contextElement is a GridRecord, then casting it to GridRecord should allow rec.GetData to return a DataRowView object (if you are using a DataTable). Also, rec.GetValue should return a particular column value if you pass in a column name. If you want a list of the column names, you can try rec.ParentTable.TableDescriptor.Fields. If the contextElement is something other than a record, then you would have to cast it to the appropriate type and access the information in that particular type.

VB vbaker October 11, 2004 12:17 PM UTC

It works as you say. Thanks a lot! --Van Baker

Live Chat Icon For mobile
Up arrow icon