Disabling ability to to select columns by Clicking one, then dragging to another

The following lines :

this.gridCtl.AllowDragSelectedCols = false;
this.gridCtl.AllowDragSelectedRows = false;

aren''''t preventing the user from MouseDown''ing on one column (like C), then dragging to another column (like F) to select those columns (C..F). It''s a standard gridctl - 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 the difference between grid.Model.Selections.* and regular grid.Selections.* (like grid.Model.Selections.Add vs. grid.Selections.Add).

Nor am I clear what the difference between Selections.Add and Selections.SelectRange are. I *think* you were previously 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

5 Replies

AD Administrator Syncfusion Team October 10, 2006 03:14 AM UTC

Hi Michael,

Issue 1: column selection and dragging.

If you want to prevent the column selection when clicked on the columnheader, you can set the AllowSelection property of the grid. Below is a code snippet

//to prevent the Column selection..
this.gridDataBoundGrid1.AllowSelection = GridSelectionFlags.Any ^ GridSelectionFlags.Column;

//to prevent the selected column dragging
this.gridDataBoundGrid1.AllowDragSelectedCols = false;

this.gridDataBoundGrid1.ControllerOptions = GridControllerOptions.All ^ GridControllerOptions.DragSelectRowOrColumn;

Issue 2 : difference between Selections.Add and Selections.SelectRange

Did I understand you correctly?
>>>>>>>>>>

Yes. The Selections.Add method only adds a GridRangeInfo to the list of selected ranges. But you can use the Selections.SelectedRange method to add or remove a GridRangeInfo from the list of selected ranges.

Let me know if this helps.

Best Regards,
Haneef


SK Sameer Khan January 16, 2009 04:08 PM UTC

How would one prevent a subset of the columns from eing dragged around?

I want to keep the first n columns static; but allow the rest of the columns from being rearranged.

This means; that not only do I want the first n columns to not move; I dont want other columns to be dropped in the first n set.

-S

>Hi Michael,

Issue 1: column selection and dragging.

If you want to prevent the column selection when clicked on the columnheader, you can set the AllowSelection property of the grid. Below is a code snippet

//to prevent the Column selection..
this.gridDataBoundGrid1.AllowSelection = GridSelectionFlags.Any ^ GridSelectionFlags.Column;

//to prevent the selected column dragging
this.gridDataBoundGrid1.AllowDragSelectedCols = false;

this.gridDataBoundGrid1.ControllerOptions = GridControllerOptions.All ^ GridControllerOptions.DragSelectRowOrColumn;

Issue 2 : difference between Selections.Add and Selections.SelectRange

Did I understand you correctly?
>>>>>>>>>>

Yes. The Selections.Add method only adds a GridRangeInfo to the list of selected ranges. But you can use the Selections.SelectedRange method to add or remove a GridRangeInfo from the list of selected ranges.

Let me know if this helps.

Best Regards,
Haneef



RC Rajadurai C Syncfusion Team January 17, 2009 08:52 AM UTC

Hi Sameer,

Thanks for your interest in Syncfusion products.

To handle column header dragging the ControllerOptions property has to be set to DragColumnHeader.

this.gridControl1.ControllerOptions = GridControllerOptions.DragColumnHeader;


To prevent a column from being dragged, QueryAllowDragColumnHeader event has to be handled.

this.gridControl1.QueryAllowDragColumnHeader += new GridQueryDragColumnHeaderEventHandler(gridControl1_QueryAllowDragColumnHeader);

void gridControl1_QueryAllowDragColumnHeader(object sender, GridQueryDragColumnHeaderEventArgs e)
{
if (e.Column == 3)
e.AllowDrag = false;
}


To prevent a column from being dropped with other column, ColsMoving event has to be handled.

private void gridControl1_ColsMoving(object sender, Syncfusion.Windows.Forms.Grid.GridRangeMovingEventArgs e)
{
if(e.Target == 3)
{
e.Cancel = true;
this.gridControl1.Cols.MoveRange(e.From,1,e.From);
}
}


Please refer to the following sample that implements this.
http://websamples.syncfusion.com//samples/Grid.Windows/F50159.zip

Regards,
Rajadurai



SK Sameer Khan January 20, 2009 07:54 PM UTC

QueryAllowDragColumn works fine; so I am now able to supress the move.


However; TableModel.ColsMoved is never called
I have set the following options:

_grid.TableModel.Options.ControllerOptions = GridControllerOptions.DragColumnHeader ^ GridControllerOptions.DragSelectRowOrColumn;

Am I missing something?


Note I am using the grid grouping control.

>Hi Sameer,

Thanks for your interest in Syncfusion products.

To handle column header dragging the ControllerOptions property has to be set to DragColumnHeader.

this.gridControl1.ControllerOptions = GridControllerOptions.DragColumnHeader;


To prevent a column from being dragged, QueryAllowDragColumnHeader event has to be handled.

this.gridControl1.QueryAllowDragColumnHeader += new GridQueryDragColumnHeaderEventHandler(gridControl1_QueryAllowDragColumnHeader);

void gridControl1_QueryAllowDragColumnHeader(object sender, GridQueryDragColumnHeaderEventArgs e)
{
if (e.Column == 3)
e.AllowDrag = false;
}


To prevent a column from being dropped with other column, ColsMoving event has to be handled.

private void gridControl1_ColsMoving(object sender, Syncfusion.Windows.Forms.Grid.GridRangeMovingEventArgs e)
{
if(e.Target == 3)
{
e.Cancel = true;
this.gridControl1.Cols.MoveRange(e.From,1,e.From);
}
}


Please refer to the following sample that implements this.
http://websamples.syncfusion.com//samples/Grid.Windows/F50159.zip

Regards,
Rajadurai





RC Rajadurai C Syncfusion Team January 23, 2009 10:55 AM UTC

Hi Sameer,

Thanks for your update.

Please try handling TableDescriptor.Columns.Changed/Changing events as these get fired when columns are moved in gridgroupingcontrol. Here is a sample code:

this.gridGroupingControl1.TableDescriptor.Columns.Changed += new Syncfusion.Collections.ListPropertyChangedEventHandler(Columns_Changed);
void Columns_Changed(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e)
{
if (e.Action == ListPropertyChangedType.Move)
MessageBox.Show("Moved");
}


Regards,
Rajadurai


Loader.
Up arrow icon