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

Row Selections & context menu

Hi folks, I've got some tiny little problems... Due to postings in this forum I was able to fix some of that, but some probs still remain. The most urgently goes like this: I've got an databound Grid, completely formatted, only complete rows can be selected, multiple selection is possible. We've got a ToolBar-Control from another vendor which we use in all our apps; I've create some contextmenu and bound it to the grid. It works fine. When I select more than one row and rightclick the grid to bring up the contextmenu, allrows but the one I've clicked on are deselected. Can you give me a hint how to keep the whole selection? Thanks in advance, Jens Schlegel@orgatex.net

4 Replies

AD Administrator Syncfusion Team April 17, 2003 09:05 AM UTC

Try handling the grid.Model.SelectionsChanging event and cancel it if the right button is down.
//hook the handler
this.gridDataBoundGrid1.Model.SelectionChanging += new GridSelectionChangingEventHandler(grid_SelectionsChanging);


private void grid_SelectionsChanging(object sender, GridSelectionChangingEventArgs e)
{
	if(Control.MouseButtons == MouseButtons.Right)
		e.Cancel = true;
}


JS Jens Schlegel April 17, 2003 09:19 AM UTC

Sorry, that didn't the trick... I use the following code: Private Sub grdMailOverViewSyncFusion_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdMailOverViewSyncFusion.Resize SetGridSizes() End Sub Private Sub grdMailOverViewSyncFusion_CurrentCellActivating(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCurrentCellActivatingEventArgs) Handles grdMailOverViewSyncFusion.CurrentCellActivating e.ColIndex = 0 End Sub Private Sub grdMailOverViewSyncFusion_CurrentCellMoving(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCurrentCellMovingEventArgs) Handles grdMailOverViewSyncFusion.CurrentCellMoving Dim Range As Syncfusion.Windows.Forms.Grid.GridRangeInfo Range = Syncfusion.Windows.Forms.Grid.GridRangeInfo.Cells(e.RowIndex, 1, e.RowIndex, 1) DisplayMail(CStr(grdMailOverViewSyncFusion.DataBoundGridModel.GetCellsInfo(Range)(0).Text)) e.ColIndex = 0 End Sub Private Sub InitializeGrid() AddHandler grdMailOverViewSyncFusion.Model.SelectionChanging, AddressOf SelectionChanging AddHandler grdMailOverViewSyncFusion.DataBoundGridModel.QueryCellInfo, AddressOf QueryCellInfo With grdMailOverViewSyncFusion .Refresh() .AllowSelection = Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Row Or Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Shift Or Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Multiple .HScrollBehavior = Syncfusion.Windows.Forms.Grid.GridScrollbarMode.Disabled .ResizeRowsBehavior = Syncfusion.Windows.Forms.Grid.GridResizeCellsBehavior.None .ResizeColsBehavior = Syncfusion.Windows.Forms.Grid.GridResizeCellsBehavior.ResizeSingle .ListBoxSelectionMode = Windows.Forms.SelectionMode.MultiExtended .TableStyle.Borders.Bottom = New Syncfusion.Windows.Forms.Grid.GridBorder(Syncfusion.Windows.Forms.Grid.GridBorderStyle.None) .TableStyle.Borders.Top = New Syncfusion.Windows.Forms.Grid.GridBorder(Syncfusion.Windows.Forms.Grid.GridBorderStyle.None) .TableStyle.Borders.Left = New Syncfusion.Windows.Forms.Grid.GridBorder(Syncfusion.Windows.Forms.Grid.GridBorderStyle.None) .TableStyle.Borders.Right = New Syncfusion.Windows.Forms.Grid.GridBorder(Syncfusion.Windows.Forms.Grid.GridBorderStyle.None) End With End Sub Private Sub QueryCellInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs) On Error Resume Next If e.RowIndex > 0 AndAlso e.ColIndex > 0 Then If e.RowIndex Mod 2 = 0 Then e.Style.BackColor = System.Drawing.Color.Silver e.Handled = True End If If e.ColIndex = 3 Then e.Style.CellType = "System.Drawing.Image" If CBool(e.Style.CellValue) = True Then e.Style.Font.Bold = True e.Style.ImageList = imlGrid e.Style.ImageIndex = 1 Else e.Style.Font.Bold = False e.Style.ImageList = imlGrid e.Style.ImageIndex = 2 End If e.Handled = True End If If e.ColIndex = 2 Then e.Style.CellType = "System.Drawing.Image" If CBool(e.Style.CellValue) = True Then e.Style.ImageList = imlGrid e.Style.ImageIndex = 0 Else e.Style.CellValue = "" End If e.Handled = True End If End If End Sub Private Sub SelectionChanging(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridSelectionChangingEventArgs) If grdMailOverViewSyncFusion.MouseButtons = Windows.Forms.MouseButtons.Right Then e.Cancel = True End If End Sub is there any other way to keep the selection if right mousebutton is clicked? Thanks, Jens js@posthann.de > Try handling the grid.Model.SelectionsChanging event and cancel it if the right button is down. > ...


AD Administrator Syncfusion Team April 17, 2003 12:15 PM UTC

The Control.MousePosition is a Shared (static in C#) property. So instead of grdMailOverViewSyncFusion.MouseButtons = Windows.Forms.MouseButtons.Right use Control.MouseButtons = Windows.Forms.MouseButtons.Right


AD Administrator Syncfusion Team April 17, 2003 12:18 PM UTC

Oops. Meant to say Control.MouseButtons is a static property (though Control.MousePosition is also a static property but that comment is off topic).

Loader.
Live Chat Icon For mobile
Up arrow icon