I am working with a data grid that currently allows selection only of a single cell, a single column. I now need to :
1. select an entire column when a single cell is selected;
2. be able to select both contiguous or non-contiguous columns (cols 3-5, or 3, 5, and 7), and show this visually.
3. programmatically select a group of columns from another component (contiguous, or non-contiguous)
Currently, when I select non-contiguous columns, only the 1st column shows up.
Let me know if you need more information.
AD
Administrator
Syncfusion Team
August 24, 2006 04:13 AM UTC
Hi Michael,
Use the Model.Selections property to manages selected ranges in the grid. It allows you to add and remove selections, determines selection state of a specific cell.
Issue 1://For single column selection
Try this code in CellClick event.
this.grid1.Model.Selections.Add(GridRangeInfo.Col(ColIndex));
Issue 2 and 3:
[Ex FromColIndex= 3; ToColIndex = 5; ExtraColIndex = 7; Below code select the 3-5 and 7 th column.]
//For Group of columns selection(3-5)
this.grid1.Model.Selections.Add(GridRangeInfo.Cols(FromColIndex,ToColIndex));
this.grid1.Model.Selections.Add(GridRangeInfo.Col(ExtraColIndex));
Thanks,
Haneef
MS
Michael Scott
September 22, 2006 12:23 AM UTC
Sorry - I got moved on to other issues temporarily. Could you expand on that?
In addition, a new requirement is to be able to manually select one of the following ONLY :
1. Multiple Rows (contiguous or non-contiguous)
2. Multiple Columns (same as above
3. A single cell (which gets converted to a single column)
Currently, I only allow clicking on a single row, single column, or single cell. I had started working on this previously, but wasn''t getting very far. In the attached file, those changes are wrapped around "#if MultiSelect"
Michael
ConfusionMatrixView.zip
AD
Administrator
Syncfusion Team
September 25, 2006 02:54 PM UTC
Hi Michael,
I have created a sample based on your requirement, to select either of your choices in selection(multiple rows / multiple cols/ single cell). Please try the attached sample and let us know if this helps.
Here is a sample
http://www.syncfusion.com/Support/user/uploads/Grid_Selection_ce6185dc.zipRegards,
Rajagopal
MS
Michael Scott
September 25, 2006 11:01 PM UTC
I was unable to compile your result. Could you send the EXE. In the meantime...
1. How can I have NO cell selected?
2. Why didn''t you use SelectionChanging event
3. How to distinguish between selecting cols 4 and 5, vs. selecting 4, and dragging to 5. I need to make sure that BOTH select both columns 4 and 5.
AD
Administrator
Syncfusion Team
September 26, 2006 05:26 AM UTC
Hi Michael,
1. How can I have NO cell selected?
>>> Use the Selections.Clear method to clear all selections in a grid.
2. Why didn''''t you use SelectionChanging event
>>>The SelectionChanging event is used to manage the process of selecting the range of cells in a grid.
3. How to distinguish between selecting cols 4 and 5, vs. selecting 4, and dragging to 5. I need to make sure that BOTH select both columns 4 and 5.
>>>>
Add the DragColumnHeader in the Controller option to enable DragColumnHeader functionality.
this.grid.ControllerOptions |= GridControllerOptions.DragColumnHeader;
and you can use QueryAllowDragColumnHeader event to find the dargging columns(4 to 5) in a grid. Below is a code snippet
private void QueryAllowDragColumnHeader(object sender, GridQueryDragColumnHeaderEventArgs e)
{
Console.WriteLine("Column Number : " + e.Column);
Console.WriteLine("Insert Before Column Number : " + e.InsertBeforeColumn );
}
Let me know if you need any further assitance.
Thanks,
Haneef
MS
Michael Scott
September 26, 2006 07:52 PM UTC
You misunderstood me. I''m not trying to drag columns from A to B. I need to tell if columns C, D, and E are selected whether I
1. I clicked on Column C, then Ctrl Clicked the rest
2. I did a MouseDown on C, and dragged to E.
3. I clicked on Column C, then Shift Clicked on Column E.
MS
Michael Scott
September 27, 2006 02:23 AM UTC
On a similar note - is there a way to DISABLE the ability to MouseDown on Col C header, then drag/select to Col F (essentially selecting columns C, D, E, and F)?
Also, what is the difference between 4 items :
gridCtl.Model.Selections.Add
(GridRangeInfo.Col(idx));
gridCtl.Model.Selections.SelectRange
(GridRangeInfo.Col(idx), true);
gridCtl.Selections.Add
(GridRangeInfo.Col(idx));
gridCtl.Selections.SelectRange
(GridRangeInfo.Col(idx), true);
MS
Michael Scott
September 27, 2006 07:46 PM UTC
Another odd one. I accidentally changed the settings in my grid class, so now when I''m in the SelectionChanging Event Handler, GridSelectionChangingEventArgs.Range.RangeType not returns GridRangeInfoType.Empty when I click on a cell, instead of GridRangeInfoType.Cells. And clicking on a cell won''t even go into my CellClick Event Handler. This is after looking at the Properties of my GridCtl.
Ideas?
Michael
AD
Administrator
Syncfusion Team
September 28, 2006 06:34 AM UTC
Hi Michael,
Is there a way to DISABLE the ability to MouseDown on Col C header, then drag/select to Col F (essentially selecting columns C, D, E, and F)?
>>>>>>>>>>>>>>>>>>>
Do you want to cancel the MouseDown event in the ColumnHeader? If so, you would have to derive the GridDataBoundControl and override the OnMouseDown event. Below is a code snippet.
private class MyGrid : Syncfusion.Windows.Forms.Grid.GridDataBoundGrid
{
protected override void OnMouseDown(MouseEventArgs e)
{
Point pt = new Point(e.X,e.Y);
int row, col;
this.PointToRowCol(pt,out row,out col);
if( row != 0 && col > 0 )
base.OnMouseDown (e);
}
}
Do you want to disable the drag selected columns by clicking on the column header in a grid? If so, you can set the AllowDragSelectedCols property to false.
this.grid.AllowDragSelectedCols = false;
What is the difference between 4 items?
>>>>>>>>>>>>>>>>>>>>>>>>>
The Selections.Add method adds a GridRangeInfo to the list of selected ranges. For example the new selection idx column range to be added.
//idx th coindex adds to be added.
gridCtl.Model.Selections.Add (GridRangeInfo.Col(idx));
The Selections.SelectedRange method adds/removes a GridRangeInfo to/from the list of selected ranges. For example the new selection idx column range to be added.
//idx th coindex adds to be added.
gridCtl.Model.Selections.SelectRange (GridRangeInfo.Col(idx), true);
For example the selection idx column range to be removed.
gridCtl.Model.Selections.SelectRange (GridRangeInfo.Col(idx), false);
Selection issue.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Try setting the ExcelLikeCurrentCell property to True and get the RangeType using the below code snippet.
this.grid.ExcelLikeCurrentCell = true;
private void Model_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
if( ( e.Reason == GridSelectionReason.MouseDown
|| e.Reason == GridSelectionReason.SetCurrentCell
|| e.Reason == GridSelectionReason.MouseMove )
&& !e.Range.IsEmpty )
{
if( e.ClickRange != null && e.Range != null )
{
Console.WriteLine( "[ Click Range ]" + e.ClickRange + "[ TYPE ]" + e.ClickRange.RangeType );
Console.WriteLine( "[ RANGE ] " + e.Range + "[ TYPE ]" + e.Range.RangeType );
}
}
}
Best Regards,
Haneef
MS
Michael Scott
September 29, 2006 04:57 PM UTC
The following lines :
this.gridCtl.AllowDragSelectedCols = false;
this.gridCtl.AllowDragSelectedRows = false;
aren''t preventing the user from clicking on one column (like C), then dragging to another column (like F) to select those columns (C..F). It''s a standard grid - does it need to be a specific type of Grid Ctl?
If I can''t disable that, how to I take advantage of that, and register which colums (or rows) were selected when I MouseUp?
I still didn''t understand your description between grid.Model.Selections.* and regular grid.Selections.*.
Nor am I clear what the difference between Selections.Add and Selections.SelectRange are. I *think* you were trying to say that Add just adds a range, where SelectRange lets you either Add or Delete a range. Did I understand you correctly?
MS
Michael Scott
October 3, 2006 10:21 PM UTC
Haneef? Other than these last two questions, I''ve gotten everything to work. But understanding these last two will be helpful