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

Active cell

How can I make the cell a user right or left clicks in the current cell and that cell''s row the current row?

9 Replies

AD Administrator Syncfusion Team January 31, 2005 08:02 PM UTC

You can handle the TableControlCellClicked event. In your event handler you could call e.TableControl.CurrentCell.MoveTo(e.Inner.RowIndex, e.Inner.ColIndex); As an alternative you could also get the cell identity using GridTableCellStyleInfo style = (GridTableCellStyleInfo) e.TableModel[e.Inner.RowIndex, e.Inner.ColIndex]; GridTableCellStyleInfoIdentity id = style.TableCellIdentity; and then call Record.SetCurrent(Field) as follows if (id.DisplayElement.ParentRecord != null && id.Column != null) id.DisplayElement.ParentRecord.SetCurrent(id.Column.FieldDescriptor.Name) Stefan


AA Anthony Avella February 1, 2005 11:48 AM UTC

This works for the left mouse button click, but not the right mouse button click. What do I need to do for the right mouse button click? >You can handle the TableControlCellClicked event. > >In your event handler you could call > >e.TableControl.CurrentCell.MoveTo(e.Inner.RowIndex, e.Inner.ColIndex); > >As an alternative you could also get the cell identity using > >GridTableCellStyleInfo style = (GridTableCellStyleInfo) e.TableModel[e.Inner.RowIndex, e.Inner.ColIndex]; >GridTableCellStyleInfoIdentity id = style.TableCellIdentity; > >and then call Record.SetCurrent(Field) as follows > >if (id.DisplayElement.ParentRecord != null && id.Column != null) >id.DisplayElement.ParentRecord.SetCurrent(id.Column.FieldDescriptor.Name) > >Stefan > >


AA Anthony Avella February 1, 2005 01:06 PM UTC

I have another problem, which is very irritating.... Anytime I click into a summary or detail cell the cursor appears, allowing me to edit the cell. As per a previous forum response we use the following line of code to allow the user to enter a summary cell for editing: grid.Appearance.GroupCaptionSummaryCell.CellType = "TextBox". But I am unable to bring up my context menu with a mouse right button click. With some complex combination of moves aroung the grid, I''m eventually able to bring up the context menu. This is completely unusable for our users. How can we let a summary cell be editable for a user and still be able to right click in the cell to bring up my context menu? >You can handle the TableControlCellClicked event. > >In your event handler you could call > >e.TableControl.CurrentCell.MoveTo(e.Inner.RowIndex, e.Inner.ColIndex); > >As an alternative you could also get the cell identity using > >GridTableCellStyleInfo style = (GridTableCellStyleInfo) e.TableModel[e.Inner.RowIndex, e.Inner.ColIndex]; >GridTableCellStyleInfoIdentity id = style.TableCellIdentity; > >and then call Record.SetCurrent(Field) as follows > >if (id.DisplayElement.ParentRecord != null && id.Column != null) >id.DisplayElement.ParentRecord.SetCurrent(id.Column.FieldDescriptor.Name) > >Stefan > >


AD Administrator Syncfusion Team February 2, 2005 05:26 PM UTC

To enable right-click to move the current cell set TableModel.Options.SelectCellsMouseButtonsMask = MouseButtons.Left|MouseButtons.Middle|MouseButtons.Right In order to be notified about right clicks in the textbox part of a textbox cell, you need to manually wire the event for this cell. You could do this in CurrentCellControlGotFocus and wire the event with e.Inner.TableControl.CurrentCell.Renderer.Control.MouseDown += new MouseEventHandler(controlMouseDown) and in CurrentCellControlLostFocus unwire the event with e.Inner.TableControl.CurrentCell.Renderer.Control.MouseDown -= new MouseEventHandler(controlMouseDown) In your controlMouseDown handler you can then display the context menu. Stefan


AA Anthony Avella February 3, 2005 03:08 PM UTC

This event handling solution you suggest does not work. In my context menu popup handler function, the object passed in is cast to a context menu - this is what''s given to us by the handler. This is the only way to obtain the conext menu from this event. Your solution tells us to create an eventhandler with the following signature: private void controlMouseDown(object sender, System.Windows.Forms.MouseEventArgs e) This sender object cannot be cast to a context menu - I''m receiving an Invalid Cast Exception when the cast is attempted. Am I missing something or is there another way to handle this situation? Please advise. Thanks. >To enable right-click to move the current cell set TableModel.Options.SelectCellsMouseButtonsMask = MouseButtons.Left|MouseButtons.Middle|MouseButtons.Right > >In order to be notified about right clicks in the textbox part of a textbox cell, you need to manually wire the event for this cell. > >You could do this in CurrentCellControlGotFocus and wire the event with > >e.Inner.TableControl.CurrentCell.Renderer.Control.MouseDown += new MouseEventHandler(controlMouseDown) > >and in CurrentCellControlLostFocus unwire the event with > > >e.Inner.TableControl.CurrentCell.Renderer.Control.MouseDown -= new MouseEventHandler(controlMouseDown) > >In your controlMouseDown handler you can then display the context menu. > >Stefan >


AD Administrator Syncfusion Team February 3, 2005 04:18 PM UTC

The sender will be a GridGroupingControl. You have to instantiate the context menu in your handler code. Stefan


AA Anthony Avella February 4, 2005 06:32 PM UTC

This does not seem to work for me. Is there any other way to do this? >The sender will be a GridGroupingControl. You have to instantiate the context menu in your handler code. > >Stefan >


AA Anthony Avella February 4, 2005 09:38 PM UTC

Unfortunately, this problem is proving to be quite obstinate. My context menu pops up if I either left click on the summary cell or if I right click in the cell 2 times (two sepatae clicks, not a double click). It seems like The summary cell needs to have the cursor blinking in it before I can bring up the menu. I only want the context menu to come up when a user right clicks one time on a summary row/cell. When I create the context menu on the fly (as you mentioned previously), I need the coordinates of where it will show on the grid. I''d like the context menu to show up on the highlighted cell. How do I get those coordinates from the grid? When we were using version 2.. of the grid for aggregation we were able to make summary cells editable by adding the following line of code for CustomCaptionRows in the grid_QueryCellStyleInfo event handler for each cell we''d like to make editable: e.Style.ReadOnly = false; . This line of code does nothing in version 3. In order to make summary cells editable we now need to make the whole summary row a textbox with the following line of code: grid.Appearance.GroupCaptionSummaryCell.CellType = "TextBox"; I bring this up here because I believe this has a lot to do with my problem. Is there any other way to make summary cells editable on an individual basis, similar to the way I did it in version 2... of the grid? Thanks. >The sender will be a GridGroupingControl. You have to instantiate the context menu in your handler code. > >Stefan >


AD Administrator Syncfusion Team February 6, 2005 09:11 PM UTC

Anthony, please take the CaptionSummaryCell example. Add the following lines in the Form1.ctor() this.gridGroupingControl1.TableControlCellClick += new GridTableControlCellClickEventHandler(gridGroupingControl1_TableControlCellClick); this.gridGroupingControl1.TableModel.Options.SelectCellsMouseButtonsMask |= MouseButtons.Right; summaryColumn1.Appearance.AnyCell.CellType = "TextBox"; summaryColumn2.Appearance.AnyCell.CellType = "TextBox"; and these lines at the end of the class: ContextMenu popupMenu; private void gridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e) { Console.WriteLine(e.Inner.ToString()); if (popupMenu == null) { popupMenu = new ContextMenu(); popupMenu.MenuItems.Add(new MenuItem("Testing")); } if (e.Inner.MouseEventArgs.Button == MouseButtons.Right) { int row = e.Inner.RowIndex, col = e.Inner.ColIndex; Point point = this.PointToClient(Control.MousePosition); Element el = e.TableControl.Table.DisplayElements[e.Inner.RowIndex]; // Columns must always be greater than zero if (col > 0 && el is CaptionRow) { e.Inner.Cancel = true; Point newPoint = e.TableControl.PointToClient(Cursor.Position); popupMenu.Show(e.TableControl, newPoint); } } } These changes will make the summary cell editable and allow a right click into the inactive cell and display a context menu. Stefan

Loader.
Live Chat Icon For mobile
Up arrow icon