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.

Data Grid - how to programmatically select rows or cols

Thread ID:

Created:

Updated:

Platform:

Replies:

48284 Aug 23,2006 08:41 PM Oct 3,2006 06:21 PM Windows Forms 11
loading
Tags: GridControl
Michael Scott
Asked On August 23, 2006 08:41 PM

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.

Administrator [Syncfusion]
Replied On August 24, 2006 12:13 AM

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

Michael Scott
Replied On September 21, 2006 08:23 PM

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

Administrator [Syncfusion]
Replied On September 25, 2006 10:54 AM

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.zip

Regards,
Rajagopal



Michael Scott
Replied On September 25, 2006 07:01 PM

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.

Administrator [Syncfusion]
Replied On September 26, 2006 01:26 AM

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

Michael Scott
Replied On September 26, 2006 03:52 PM

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.

Michael Scott
Replied On September 26, 2006 10:23 PM

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);

Michael Scott
Replied On September 27, 2006 03:46 PM

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

Administrator [Syncfusion]
Replied On September 28, 2006 02:34 AM

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

Michael Scott
Replied On September 29, 2006 12:57 PM

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?

Michael Scott
Replied On October 3, 2006 06:21 PM

Haneef? Other than these last two questions, I''ve gotten everything to work. But understanding these last two will be helpful

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.

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.

;