I'm trying to implement a sticky grid-cell selection scheme for a grid that models a chemistry vial rack (it uses the cell rendering class to draw custom graphics and doesn't use the normal text features of the grid ).
I'm having troubles detecting if a cell is selected or not. For example, the following vb.net function doesn't work correctly because it always returns TRUE even when the cell is not selected:
Public Function IsCellSelected(ByVal nRow%, ByVal nCol%) As Boolean
Dim bSelected As Boolean = myGrid.Selections.Ranges.AnyRangeContains(GridRangeInfo.Cells(nRow, nCol, nRow, nCol))
I guess I'm wondering what I'm doing wrong as it relates to the AnyRangeContains() function. It appears that it's always returning TRUE for some reason even when nothing is selected. (I also tried the Intersects method with the same result.)
ADAdministrator Syncfusion Team November 7, 2002 05:50 AM
I tested your code snippet with the soon-to-be- released 1.5 version, and did not see a problem with the AnyRangeContains method. It returned true or false as expected.
Do you have the ExcelLikeCurrentCell property set to true?
If so, then the currentcell will always be considered as selected. That might be why you never see a false from AnyRangeContains.
RMRollan MoskoNovember 7, 2002 04:41 PM
I changed the ExcelLikeCurrentCell property to be false and now I always get FALSE answers back. The end result is about the same.
I noticed a couple of other things:
1. The current selected cell has the box (no shading). How can I make the current cell grey the same as additional selected cells? I was hoping changing ExcelLikeCurrentCell to FALSE would resolve that but maybe this is a different trait?
2. The _CellClick event is not the place to handle sticky selection since the selection appears to clear earlier.
3. Things work best when I select entire rows/columns by selecting the margins of the grid. I can then unselect using the existing logic.
I'm attaching a .zip for my control so you can have a better idea of what I'm trying to do.
ADAdministrator Syncfusion Team November 8, 2002 03:53 AM
I switched your control to a Form, and here is what I saw.
I could drag over several cells in the grid to select them. But as soon as you do a mousedown on one of the selected cells to trigger your call to Cell_Click which calls your ToggleCellSelection which calls the IsCellSelected, the selections are lost. This is because the mousedown is unselecting everything at that point. So, you have to be able to distinguish between a mousedown that is teh start of a selecting cells process, and a mousedown that is the start of a Cell_click where you want to call ToggleCellSelection.
How you go about this depends upon your goal. DO you want to allow the user to select a range of cells, and then click on a single cell in that range to unselect the single cell, but not the other cells in the selected ranges. Right now, the click clears all selections on the mousedown, so by the time you get to the click event(which happens after the mouseup), there are no selections.
If you explain a little more about what behavior you need, then maybe we can make some suggestions as to how to implement it.
Hopefully, I did not misunderstand what you were doing here.
RMRollan MoskoNovember 20, 2002 03:04 PM
Sorry for the time lag, but I got stuck on a Visual Studio 6 assignment the last few weeks.
What you noticed is exactly the problem I would love to solve. It sounds like I might need to add a property to my grid control class for how OnClick works. I'll need to determine if the click is part of a drag selection or if it's simply a single cell click event. I haven't done this yet in .NET so I'll need to investigate - perhaps I need to handle the MouseMove like event?
The user goal is to mark each cell in the grid. I
thought leveraging off selection as the best means of doing this since so much logic is already in place. Each cell position is associated with a physical vial location on our control system. I thought the easiest thing for the user would be to click/drag the cells (vial locations in their mind) that need to be processed. By clicking again, they can toggle between selecting or unselecting the given cells. I noticed clicking row/col headers does this right now, I'd like to make selecting by dragging across cells work similarly to the row/col selection scheme.
These grids can contain up to 96 samples so users like the idea selecting a large area of cells and then subtracting later. Some users might have samples in non-contiguous locations so the sticky select scheme would work great for them because they could click A1,B2,C3,D4, ect. if they needed to select a diagonal for some reason.
I hope this clarifies things better and will be monitoring this forum more regularly now. I'd appreciate any comments or suggestions you have on this.
p.s. Installed 1.5 today and this appears to be a major release with lots of neat samples and improved documentation. I just got my app to work after rebuilding most of the .resx files so I haven't spent a lot of time using it yet but what I see is great.
Keep up the good work :-)
> I switched your control to a Form, and here is what I saw.
> I could drag over several cells in the grid to select them. But as soon as you do a mousedown on one of the selected cells to trigger your call to Cell_Click which calls your ToggleCellSelection which calls the IsCellSelected, the selections are lost. This is because the mousedown is unselecting everything at that point. So, you have to be able to distinguish between a mousedown that is teh start of a selecting cells process, and a mousedown that is the start of a Cell_click where you want to call ToggleCellSelection.
====> RJM COMMENT: If I detect dragging perhaps I can do the normal cell selection logic (clear selection first). If I do a single click then maybe I can call my logic for toggling the selection?
> How you go about this depends upon your goal. DO you want to allow the user to select a range of cells, and then click on a single cell in that range to unselect the single cell, but not the other cells in the selected ranges. Right now, the click clears all selections on the mousedown, so by the time you get to the click event(which happens after the mouseup), there are no selections.
> If you explain a little more about what behavior you need, then maybe we can make some suggestions as to how to implement it.
> Hopefully, I did not misunderstand what you were doing here.
ADAdministrator Syncfusion Team November 20, 2002 03:54 PM
Exactly what behavior do you want?
When you mousedown and mouseup on the same cell, do you want to toggle the selected state of that cell?
When you mousedown on one cell, but mouseup on another, what do you want to happen? Do you want the selection state of any cell in the range to be toggled?
RMRollan MoskoNovember 21, 2002 09:45 AM
I'd like the following:
1. mouseup/down on same cell: toggle cell selection (and preserve existing cell selections)
2. continue to have the ability to select row/col headers and have that select the cells associated with the row or column
ADAdministrator Syncfusion Team November 21, 2002 04:14 PM
Here is a sample that does this. It triggers everything off the MouseDown event. It also treats all selections as single cell selections. So, if you click a row header, you add a 1 cell selection for each cell in the row. This allows you to click the cell to remove the single cell selection. If it were part of a row selection, you could not just remove the single cell.
ADAdministrator Syncfusion Team November 22, 2002 01:37 AM
Also, you should note that the AllowSelection property was changed to not allow Row or Column selections since these are being handled in mousedown as a seires of 1-cell selections.
RMRollan MoskoNovember 22, 2002 11:20 AM
Thanks a bunch. That's what I needed.
I found having the AllowSelection set to ANY causes bazarre selection problems so clearing this made everything work just dandy.
NSNoah ShipleyMarch 5, 2012 10:43 PM
May I have this sample too?
RBRagamathulla B Syncfusion Team March 9, 2012 04:02 AM
Thank you for your interest in syncfusion products.
1) You can enable the selection by Allowselection property. The following code explains the same.
2) you can get the selection ranges by using mouseup event. The following code is illustrates the same.
// selection ranges
For i As Integer = 0 To Me.gridControl1.ColCount For j As Integer = 0 To Me.gridControl1.RowCount If Me.gridControl1.Selections.Ranges.ActiveRange.IntersectsWith(GridRangeInfo.Cell(j, i)) Then textBox1.Text = (Integer.Parse(textBox1.Text) + Integer.Parse(Me.gridControl1.Model(j, i).Text)).ToString() End If Next j Next i
3) 'Excel-Style selection' which is available in our dashboard Please refer to the following path.