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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How can I use shift key to select multiple dates?

How can I use shift key to select multiple dates?

 

To achieve multiple selection using Shift key instead of control key, you need to access the GridControl from the MonthCalendarAdv control. Then you need to handle GridCellClick event and add selected cells in Selections list of the grid. Please refer to the following code snippet.

C#

public void SetUpMonthCalendar(MonthCalendarAdv ctrlMonthAdv)

{

ctrlMonthAdv.AllowMultipleSelection = false;

foreach (Control ctl1 in ctrlMonthAdv.Controls)

{

GridControl _crlGrid = ctl1 as GridControl;

if (_crlGrid != null)

{

_crlGrid.Focus();

_crlGrid.MouseDown += new MouseEventHandler(GridMouseDownForSelection);

_crlGrid.PrepareChangeSelection += new GridPrepareChangeSelectionEventHandler(_crlGrid_PrepareChangeSelection);

_crlGrid.PrepareClearSelection += new EventHandler(_crlGrid_PrepareClearSelection);

_crlGrid.AllowSelection = GridSelectionFlags.AlphaBlend | GridSelectionFlags.Shift;

_crlGrid.MouseMove += new MouseEventHandler(_crlGrid_MouseMove);

_crlGrid.CellClick += new GridCellClickEventHandler(_crlGrid_CellClick);

break;

}

}

}

//Grid CellClick event

void _crlGrid_CellClick(object sender, GridCellClickEventArgs e)

{

GridControl _crlGrid = sender as GridControl;

if (Control.ModifierKeys == Keys.Shift)

{

GridRangeInfo range = _crlGrid.CurrentCell.RangeInfo;

if (IsFirstClick)

{

range = GridRangeInfo.Cell(FirstRowIndex, FirstColIndex);

IsFirstClick = false;

}

int row, col;

if (_crlGrid.PointToRowCol(e.MouseEventArgs.Location, out row, out col))

{

//Adding selected cells in Grid selection list

_crlGrid.Model.Selections.Add(GridRangeInfo.Cells(range.Top, range.Left, row, col));

}

_crlGrid.Refresh();

}

}

VB

Public Sub SetUpMonthCalendar(ByVal ctrlMonthAdv As Syncfusion.Windows.Forms.Tools.MonthCalendarAdv)

ctrlMonthAdv.AllowMultipleSelection = False

For Each ctl1 As Control In ctrlMonthAdv.Controls

Dim _crlGrid As Syncfusion.Windows.Forms.Grid.GridControl = CType(IIf(TypeOf ctl1 Is Syncfusion.Windows.Forms.Grid.GridControl, ctl1, Nothing), Syncfusion.Windows.Forms.Grid.GridControl)

If Not _crlGrid Is Nothing Then

_crlGrid.Focus()

_crlGrid.AllowSelection = Syncfusion.Windows.Forms.Grid.GridSelectionFlags.AlphaBlend Or Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Shift

AddHandler _crlGrid.MouseMove, AddressOf _crlGrid_MouseMove

AddHandler _crlGrid.CellClick, AddressOf _crlGrid_CellClick

Exit For

End If

Next ctl1

End Sub

‘Grid CellClick event

Private Sub _crlGrid_CellClick(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs)

Dim _crlGrid As Syncfusion.Windows.Forms.Grid.GridControl = CType(IIf(TypeOf sender Is Syncfusion.Windows.Forms.Grid.GridControl, sender, Nothing), Syncfusion.Windows.Forms.Grid.GridControl)

If Control.ModifierKeys = Keys.Shift Then

Dim range As Syncfusion.Windows.Forms.Grid.GridRangeInfo = _crlGrid.CurrentCell.RangeInfo

If IsFirstClick Then

range = Syncfusion.Windows.Forms.Grid.GridRangeInfo.Cell(FirstRowIndex, FirstColIndex)

IsFirstClick = False

End If

Dim row, col As Integer

If _crlGrid.PointToRowCol(e.MouseEventArgs.Location, row, col) Then

‘Adding selected cells in Grid selection list

_crlGrid.Model.Selections.Add(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Cells(range.Top, range.Left, row, col))

End If

_crlGrid.Refresh()

End If

End Sub

Here is the sample

http://help.syncfusion.com/support/samples/KB/Tools.Windows/MultipleSelection_in_Calender/Calender.zip

 

Article ID: Published Date: Last Revised Date: Platform: Control:
1723 04/30/2011 10/15/2014 WinForms MonthCalendarAdv
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon 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.Close Icon