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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Context menu will not show in ggc until ther are selected records. Please help

Thread ID:

Created:

Updated:

Platform:

Replies:

55808 Feb 5,2007 05:16 PM UTC Feb 6,2007 10:42 PM UTC Windows Forms 3
loading
Tags: GridControl
James Blibo
Asked On February 5, 2007 05:16 PM UTC

I want to accomplish the following...

1. I have a grid in which I want to be able to multi-select rows.
2. I want to maintain my selection when I do a right-click on the ggc so that I can take some actions on the the selected records.
3. I also want to maintain my selection unless a certain column index are clicked. For example, if I have 5 columns, only the last two columns should toggle my selection.


I have the following settings..
this.gridGroupingControl2.TableControl.Selections.Clear();
this.gridGroupingControl2.TableOptions.AllowSelection = GridSelectionFlags.None;
this.gridGroupingControl2.TableOptions.ListBoxSelectionMode = SelectionMode.MultiSimple;
this.gridGroupingControl2.TableModel.Options.SelectCellsMouseButtonsMask = MouseButtons.Left;


I am handling the following event for my context menu....

private void gridGroupingControl2_TableControlCellClick(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellClickEventArgs e)
{
GridTableCellStyleInfo style = e.TableControl.Model[e.Inner.RowIndex, e.Inner.ColIndex];
if (style.TableCellIdentity.ColIndex == 1 && style.TableCellIdentity.TableCellType == GridTableCellType.ColumnHeaderCell)
e.Inner.Cancel = true;

if (e.Inner.MouseEventArgs.Button == MouseButtons.Right)
{
int row, col;
Point pt = new Point(e.Inner.MouseEventArgs.X, e.Inner.MouseEventArgs.Y);
if (e.TableControl.PointToRowCol(pt, out row, out col))
e.TableControl.CurrentCell.AdjustRowColIfCoveredCell(ref row, ref col);

tableCellStyle = e.TableControl.GetTableViewStyleInfo(row, col);
contextElement = tableCellStyle.TableCellIdentity.DisplayElement;

this.contextMenu.Items.Clear();
if (contextElement is GridRecordRow)
{
this.contextMenu.Items.Add("Combine", null, new EventHandler(on_item_clicked));
this.contextMenu1.Show(this, this.PointToClient(Control.MousePosition));
}

}



... however, the context menu will not come up until I right-click in the CURRENT cell of the CURRENTLY selected row.

When I right click on a row that is not selected, nothing happens.

Please help!


Administrator [Syncfusion]
Replied On February 5, 2007 07:36 PM UTC

Hi James,

I am not sure that the forum #55810 was also created by you, which has been updated. Please let me know if you need any further assistance.

Best Regards,
Haneef

James Blibo
Replied On February 6, 2007 07:52 AM UTC

i would appreciate it if you can provide a solution. thanks.

Administrator [Syncfusion]
Replied On February 6, 2007 10:42 PM UTC

Hi James,

1. I have a grid in which I want to be able to multi-select rows.
>>>>>>>>>>
In the GridGroupingControl, there are couple of Slection mechanisms. If you want to select rows, please use the RecordBased slections.

You need to turn off the AllowSelection to None and set the Grid.TableOptions.ListBoxSelection Mode to MultiExtanded/MultiSimple.

Please refer this shipping sample:
\windows\Grid.Grouping.Windows\Samples\GroupingGridOptions\TableOptions\
\windows\Grid.Grouping.Windows\Samples\FeatureSamples\MultipleRecordSelection

Also refer to the following knowledge base article for more details.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=344

2. I want to maintain my selection when I do a right-click on the ggc so that I can take some actions on the the selected records.
>>>>>>>>>>
Try setting the SelectCellsMouseButtonsMask property to MouseButtons.Left;

this.gridGroupingControl1.TableControl.Model.Options.SelectCellsMouseButtonsMask = MouseButtons.Left;

3. I also want to maintain my selection unless a certain column index are clicked. For example, if I have 5 columns, only the last two columns should toggle my selection.
>>>>>>>>>>
This is can be achieved by handling the SelectedRecordsChanging event of the grid and set e.Cancel to true for required column. Here is a code snippet to show this.

private void gridGroupingControl1_SelectedRecordsChanging(object sender, SelectedRecordsChangedEventArgs e)
{
string tName = e.Table.TableDescriptor.Name;
GridGroupingControl grid = sender as GridGroupingControl;
GridTableControl tc = grid.GetTableControl(tName);
int row,col;
if( tc.PointToRowCol(grid.PointToClient(MousePosition),out row,out col)
&& col == 4)
e.Cancel = true;
}

4. Showing the contextMenu in a Grid.
>>>>>>>>>
You can handle the TableControlmouseDown event of the grid and show the context menu for the GridRecord. Here is a code snippet

private void gridGroupingControl1_TableControlMouseDown(object sender, GridTableControlMouseEventArgs e)
{
if(e.Inner.Button == MouseButtons.Right )
{
int row, col;
Point pt = new Point(e.Inner.X, e.Inner.Y);
if (e.TableControl.PointToRowCol(pt, out row, out col))
e.TableControl.CurrentCell.AdjustRowColIfCoveredCell(ref row, ref col);

GridTableCellStyleInfo tableCellStyle = e.TableControl.GetTableViewStyleInfo(row, col);
Element contextElement = tableCellStyle.TableCellIdentity.DisplayElement;
this.contextMenu1.MenuItems.Clear();
if (contextElement is GridRecordRow)
{
this.contextMenu1.MenuItems.Add("Combine");
this.contextMenu1.Show(this, this.PointToClient(Control.MousePosition));
}
}
}

Please refer to the attached sample for more details.
GGC_Group_91041887.zip

Best regards,
Haneef

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;