作成日: 2017/07/26 最終更新日: 2017/07/26
文書種別
使用方法
詳細
CalendarGridには、セルの値をドラッグ&ドロップで移動する機能は用意されていませんが、GcCalendarGridのMouseDown、DragDrop、DragOverイベントを使用することで実現することが可能です。
アポイントメント型セル(AppointmentCell)や結合されたセルを移動する場合には、セルの値と一緒に結合されたセルの数も移動する必要があります。
[Visual Basic]
Imports GrapeCity.Win.CalendarGrid
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' セル型を設定します。
Dim appointmentCellType As New CalendarAppointmentCellType()
' テンプレートを設定します。
Dim template As New CalendarTemplate()
template.ColumnHeaderRowCount = 2
template.RowCount = 2
template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{YearMonth}"
template.ColumnHeader.Rows(0).Cells(0).AutoMergeMode = AutoMergeMode.Horizontal
template.ColumnHeader.Columns(0).Width = 20
template.ColumnHeader.Rows(1).Cells(0).DateFormat = "{Day}"
template.Content.Rows(0).Cells(0).Name = "myCell1"
template.Content.Rows(0).Cells(0).CellType = appointmentCellType.Clone()
template.Content.Rows(0).Cells(0).CellStyleName = "defaultStyle"
template.Content.Rows(1).Cells(0).Name = "myCell2"
template.Content.Rows(1).Cells(0).CellType = appointmentCellType.Clone()
template.Content.Rows(1).Cells(0).CellStyleName = "defaultStyle"
GcCalendarGrid1.Template = template
' カレンダーの表示形式を設定します。
Dim listView As New CalendarListView()
listView.DayCount = 30
GcCalendarGrid1.CalendarView = listView
GcCalendarGrid1.AllowDrop = True
AddHandler GcCalendarGrid1.MouseDown, AddressOf GcCalendarGrid1_MouseDown
AddHandler GcCalendarGrid1.DragDrop, AddressOf gcCalendarGrid1_DragDrop
AddHandler GcCalendarGrid1.DragOver, AddressOf GcCalendarGrid1_DragOver
' サンプルデータを作成します。
Dim today As DateTime = DateTime.Today
GcCalendarGrid1.Content(today).Rows(1).Cells(0).Value = "サンプルデータ"
GcCalendarGrid1.Content(today).Rows(1).Cells(0).ColumnSpan = 5
GcCalendarGrid1.ScrollIntoView(today)
End Sub
Private Sub GcCalendarGrid1_MouseDown(sender As Object, e As MouseEventArgs)
Dim gcCalendarGrid = DirectCast(sender, GcCalendarGrid)
Dim hitTestInfo As CalendarHitTestInfo = gcCalendarGrid.HitTest(New Point(e.X, e.Y))
If hitTestInfo.HitTestType = CalendarHitTestType.Content Then
Dim sourceCellPosition As CalendarCellPosition = hitTestInfo.CellPosition
gcCalendarGrid.DoDragDrop(sourceCellPosition, DragDropEffects.Move)
End If
End Sub
Private Sub gcCalendarGrid1_DragDrop(sender As Object, e As DragEventArgs)
Dim gcCalendarGrid = TryCast(sender, GcCalendarGrid)
Dim clientPoint As Point = gcCalendarGrid.PointToClient(New Point(e.X, e.Y))
Dim hitTestInfo As CalendarHitTestInfo = gcCalendarGrid.HitTest(New Point(clientPoint.X, clientPoint.Y))
Dim sourceCellPosition As CalendarCellPosition = DirectCast(e.Data.GetData(GetType(CalendarCellPosition)), CalendarCellPosition)
Dim destCellPosition As CalendarCellPosition = hitTestInfo.CellPosition
If sourceCellPosition <> destCellPosition Then
MoveCellValue(gcCalendarGrid, sourceCellPosition, destCellPosition)
End If
End Sub
Private Sub MoveCellValue(gcCalendarGrid As GcCalendarGrid, source As CalendarCellPosition, dest As CalendarCellPosition)
' 同じ行の場合にだけ、セルの値を移動します。
If dest.Scope = CalendarTableScope.Content And dest.RowIndex = source.RowIndex Then
' 値と結合セルの数を移動します。
gcCalendarGrid.Content(dest.Date).Rows(dest.RowIndex).Cells(dest.ColumnIndex).Value = gcCalendarGrid.Content(source.Date).Rows(source.RowIndex).Cells(source.ColumnIndex).Value
gcCalendarGrid.Content(dest.Date).Rows(dest.RowIndex).Cells(dest.ColumnIndex).ColumnSpan = gcCalendarGrid.Content(source.Date).Rows(source.RowIndex).Cells(source.ColumnIndex).ColumnSpan
' 元のセルを初期化します。
gcCalendarGrid.Content(source.Date).Rows(source.RowIndex).Cells(source.ColumnIndex).Value = Nothing
gcCalendarGrid.Content(source.Date).Rows(source.RowIndex).Cells(source.ColumnIndex).ColumnSpan = 1
' 移動先のセルを現在のセルに設定します。
gcCalendarGrid.CurrentCellPosition = New CalendarCellPosition(dest.Date, dest.RowIndex, dest.ColumnIndex)
End If
End Sub
Private Sub GcCalendarGrid1_DragOver(sender As Object, e As DragEventArgs)
e.Effect = DragDropEffects.Move
End Sub
[C#]
using GrapeCity.Win.CalendarGrid;
private void Form1_Load(object sender, EventArgs e)
{
// セル型を設定します。
var appointmentCellType = new CalendarAppointmentCellType();
// テンプレートを設定します。
var template = new CalendarTemplate();
template.ColumnHeaderRowCount = 2;
template.RowCount = 2;
template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{YearMonth}";
template.ColumnHeader.Rows[0].Cells[0].AutoMergeMode = AutoMergeMode.Horizontal;
template.ColumnHeader.Columns[0].Width = 20;
template.ColumnHeader.Rows[1].Cells[0].DateFormat = "{Day}";
template.Content.Rows[0].Cells[0].Name = "myCell1";
template.Content.Rows[0].Cells[0].CellType = appointmentCellType.Clone();
template.Content.Rows[0].Cells[0].CellStyleName = "defaultStyle";
template.Content.Rows[1].Cells[0].Name = "myCell2";
template.Content.Rows[1].Cells[0].CellType = appointmentCellType.Clone();
template.Content.Rows[1].Cells[0].CellStyleName = "defaultStyle";
gcCalendarGrid1.Template = template;
// カレンダーの表示形式を設定します。
var listView = new CalendarListView();
listView.DayCount = 30;
gcCalendarGrid1.CalendarView = listView;
gcCalendarGrid1.AllowDrop = true;
gcCalendarGrid1.MouseDown += gcCalendarGrid1_MouseDown;
gcCalendarGrid1.DragDrop += gcCalendarGrid1_DragDrop;
gcCalendarGrid1.DragOver += gcCalendarGrid1_DragOver;
// サンプルデータを作成します。
var today = DateTime.Today;
gcCalendarGrid1.Content[today].Rows[1].Cells[0].Value = "サンプルデータ";
gcCalendarGrid1.Content[today].Rows[1].Cells[0].ColumnSpan = 5;
gcCalendarGrid1.ScrollIntoView(today);
}
void gcCalendarGrid1_MouseDown(object sender, MouseEventArgs e)
{
var gcCalendarGrid = sender as GcCalendarGrid;
CalendarHitTestInfo hitTestInfo = gcCalendarGrid.HitTest(new Point(e.X, e.Y));
if (hitTestInfo.HitTestType == CalendarHitTestType.Content)
{
CalendarCellPosition sourceCellPosition = hitTestInfo.CellPosition;
gcCalendarGrid.DoDragDrop(sourceCellPosition, DragDropEffects.Move);
}
}
void gcCalendarGrid1_DragDrop(object sender, DragEventArgs e)
{
var gcCalendarGrid = sender as GcCalendarGrid;
Point clientPoint = gcCalendarGrid.PointToClient(new Point(e.X, e.Y));
CalendarHitTestInfo hitTestInfo = gcCalendarGrid.HitTest(new Point(clientPoint.X, clientPoint.Y));
CalendarCellPosition sourceCellPosition = (CalendarCellPosition)e.Data.GetData(typeof(CalendarCellPosition));
CalendarCellPosition destCellPosition = hitTestInfo.CellPosition;
if (sourceCellPosition != destCellPosition)
{
MoveCellValue(gcCalendarGrid, sourceCellPosition, destCellPosition);
}
}
private void MoveCellValue(GcCalendarGrid gcCalendarGrid, CalendarCellPosition source, CalendarCellPosition dest)
{
// 同じ行の場合にだけ、セルの値を移動します。
if (dest.Scope == CalendarTableScope.Content && dest.RowIndex == source.RowIndex)
{
// 値と結合セルの数を移動します。
gcCalendarGrid.Content[dest.Date].Rows[dest.RowIndex].Cells[dest.ColumnIndex].Value = gcCalendarGrid.Content[source.Date].Rows[source.RowIndex].Cells[source.ColumnIndex].Value;
gcCalendarGrid.Content[dest.Date].Rows[dest.RowIndex].Cells[dest.ColumnIndex].ColumnSpan = gcCalendarGrid.Content[source.Date].Rows[source.RowIndex].Cells[source.ColumnIndex].ColumnSpan;
// 元のセルを初期化します。
gcCalendarGrid.Content[source.Date].Rows[source.RowIndex].Cells[source.ColumnIndex].Value = null;
gcCalendarGrid.Content[source.Date].Rows[source.RowIndex].Cells[source.ColumnIndex].ColumnSpan = 1;
// 移動先のセルを現在のセルに設定します。
gcCalendarGrid.CurrentCellPosition = new CalendarCellPosition(dest.Date, dest.RowIndex, dest.ColumnIndex);
}
}
void gcCalendarGrid1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
アポイントメント型セル(AppointmentCell)や結合されたセルを移動する場合には、セルの値と一緒に結合されたセルの数も移動する必要があります。
[Visual Basic]
Imports GrapeCity.Win.CalendarGrid
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' セル型を設定します。
Dim appointmentCellType As New CalendarAppointmentCellType()
' テンプレートを設定します。
Dim template As New CalendarTemplate()
template.ColumnHeaderRowCount = 2
template.RowCount = 2
template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{YearMonth}"
template.ColumnHeader.Rows(0).Cells(0).AutoMergeMode = AutoMergeMode.Horizontal
template.ColumnHeader.Columns(0).Width = 20
template.ColumnHeader.Rows(1).Cells(0).DateFormat = "{Day}"
template.Content.Rows(0).Cells(0).Name = "myCell1"
template.Content.Rows(0).Cells(0).CellType = appointmentCellType.Clone()
template.Content.Rows(0).Cells(0).CellStyleName = "defaultStyle"
template.Content.Rows(1).Cells(0).Name = "myCell2"
template.Content.Rows(1).Cells(0).CellType = appointmentCellType.Clone()
template.Content.Rows(1).Cells(0).CellStyleName = "defaultStyle"
GcCalendarGrid1.Template = template
' カレンダーの表示形式を設定します。
Dim listView As New CalendarListView()
listView.DayCount = 30
GcCalendarGrid1.CalendarView = listView
GcCalendarGrid1.AllowDrop = True
AddHandler GcCalendarGrid1.MouseDown, AddressOf GcCalendarGrid1_MouseDown
AddHandler GcCalendarGrid1.DragDrop, AddressOf gcCalendarGrid1_DragDrop
AddHandler GcCalendarGrid1.DragOver, AddressOf GcCalendarGrid1_DragOver
' サンプルデータを作成します。
Dim today As DateTime = DateTime.Today
GcCalendarGrid1.Content(today).Rows(1).Cells(0).Value = "サンプルデータ"
GcCalendarGrid1.Content(today).Rows(1).Cells(0).ColumnSpan = 5
GcCalendarGrid1.ScrollIntoView(today)
End Sub
Private Sub GcCalendarGrid1_MouseDown(sender As Object, e As MouseEventArgs)
Dim gcCalendarGrid = DirectCast(sender, GcCalendarGrid)
Dim hitTestInfo As CalendarHitTestInfo = gcCalendarGrid.HitTest(New Point(e.X, e.Y))
If hitTestInfo.HitTestType = CalendarHitTestType.Content Then
Dim sourceCellPosition As CalendarCellPosition = hitTestInfo.CellPosition
gcCalendarGrid.DoDragDrop(sourceCellPosition, DragDropEffects.Move)
End If
End Sub
Private Sub gcCalendarGrid1_DragDrop(sender As Object, e As DragEventArgs)
Dim gcCalendarGrid = TryCast(sender, GcCalendarGrid)
Dim clientPoint As Point = gcCalendarGrid.PointToClient(New Point(e.X, e.Y))
Dim hitTestInfo As CalendarHitTestInfo = gcCalendarGrid.HitTest(New Point(clientPoint.X, clientPoint.Y))
Dim sourceCellPosition As CalendarCellPosition = DirectCast(e.Data.GetData(GetType(CalendarCellPosition)), CalendarCellPosition)
Dim destCellPosition As CalendarCellPosition = hitTestInfo.CellPosition
If sourceCellPosition <> destCellPosition Then
MoveCellValue(gcCalendarGrid, sourceCellPosition, destCellPosition)
End If
End Sub
Private Sub MoveCellValue(gcCalendarGrid As GcCalendarGrid, source As CalendarCellPosition, dest As CalendarCellPosition)
' 同じ行の場合にだけ、セルの値を移動します。
If dest.Scope = CalendarTableScope.Content And dest.RowIndex = source.RowIndex Then
' 値と結合セルの数を移動します。
gcCalendarGrid.Content(dest.Date).Rows(dest.RowIndex).Cells(dest.ColumnIndex).Value = gcCalendarGrid.Content(source.Date).Rows(source.RowIndex).Cells(source.ColumnIndex).Value
gcCalendarGrid.Content(dest.Date).Rows(dest.RowIndex).Cells(dest.ColumnIndex).ColumnSpan = gcCalendarGrid.Content(source.Date).Rows(source.RowIndex).Cells(source.ColumnIndex).ColumnSpan
' 元のセルを初期化します。
gcCalendarGrid.Content(source.Date).Rows(source.RowIndex).Cells(source.ColumnIndex).Value = Nothing
gcCalendarGrid.Content(source.Date).Rows(source.RowIndex).Cells(source.ColumnIndex).ColumnSpan = 1
' 移動先のセルを現在のセルに設定します。
gcCalendarGrid.CurrentCellPosition = New CalendarCellPosition(dest.Date, dest.RowIndex, dest.ColumnIndex)
End If
End Sub
Private Sub GcCalendarGrid1_DragOver(sender As Object, e As DragEventArgs)
e.Effect = DragDropEffects.Move
End Sub
[C#]
using GrapeCity.Win.CalendarGrid;
private void Form1_Load(object sender, EventArgs e)
{
// セル型を設定します。
var appointmentCellType = new CalendarAppointmentCellType();
// テンプレートを設定します。
var template = new CalendarTemplate();
template.ColumnHeaderRowCount = 2;
template.RowCount = 2;
template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{YearMonth}";
template.ColumnHeader.Rows[0].Cells[0].AutoMergeMode = AutoMergeMode.Horizontal;
template.ColumnHeader.Columns[0].Width = 20;
template.ColumnHeader.Rows[1].Cells[0].DateFormat = "{Day}";
template.Content.Rows[0].Cells[0].Name = "myCell1";
template.Content.Rows[0].Cells[0].CellType = appointmentCellType.Clone();
template.Content.Rows[0].Cells[0].CellStyleName = "defaultStyle";
template.Content.Rows[1].Cells[0].Name = "myCell2";
template.Content.Rows[1].Cells[0].CellType = appointmentCellType.Clone();
template.Content.Rows[1].Cells[0].CellStyleName = "defaultStyle";
gcCalendarGrid1.Template = template;
// カレンダーの表示形式を設定します。
var listView = new CalendarListView();
listView.DayCount = 30;
gcCalendarGrid1.CalendarView = listView;
gcCalendarGrid1.AllowDrop = true;
gcCalendarGrid1.MouseDown += gcCalendarGrid1_MouseDown;
gcCalendarGrid1.DragDrop += gcCalendarGrid1_DragDrop;
gcCalendarGrid1.DragOver += gcCalendarGrid1_DragOver;
// サンプルデータを作成します。
var today = DateTime.Today;
gcCalendarGrid1.Content[today].Rows[1].Cells[0].Value = "サンプルデータ";
gcCalendarGrid1.Content[today].Rows[1].Cells[0].ColumnSpan = 5;
gcCalendarGrid1.ScrollIntoView(today);
}
void gcCalendarGrid1_MouseDown(object sender, MouseEventArgs e)
{
var gcCalendarGrid = sender as GcCalendarGrid;
CalendarHitTestInfo hitTestInfo = gcCalendarGrid.HitTest(new Point(e.X, e.Y));
if (hitTestInfo.HitTestType == CalendarHitTestType.Content)
{
CalendarCellPosition sourceCellPosition = hitTestInfo.CellPosition;
gcCalendarGrid.DoDragDrop(sourceCellPosition, DragDropEffects.Move);
}
}
void gcCalendarGrid1_DragDrop(object sender, DragEventArgs e)
{
var gcCalendarGrid = sender as GcCalendarGrid;
Point clientPoint = gcCalendarGrid.PointToClient(new Point(e.X, e.Y));
CalendarHitTestInfo hitTestInfo = gcCalendarGrid.HitTest(new Point(clientPoint.X, clientPoint.Y));
CalendarCellPosition sourceCellPosition = (CalendarCellPosition)e.Data.GetData(typeof(CalendarCellPosition));
CalendarCellPosition destCellPosition = hitTestInfo.CellPosition;
if (sourceCellPosition != destCellPosition)
{
MoveCellValue(gcCalendarGrid, sourceCellPosition, destCellPosition);
}
}
private void MoveCellValue(GcCalendarGrid gcCalendarGrid, CalendarCellPosition source, CalendarCellPosition dest)
{
// 同じ行の場合にだけ、セルの値を移動します。
if (dest.Scope == CalendarTableScope.Content && dest.RowIndex == source.RowIndex)
{
// 値と結合セルの数を移動します。
gcCalendarGrid.Content[dest.Date].Rows[dest.RowIndex].Cells[dest.ColumnIndex].Value = gcCalendarGrid.Content[source.Date].Rows[source.RowIndex].Cells[source.ColumnIndex].Value;
gcCalendarGrid.Content[dest.Date].Rows[dest.RowIndex].Cells[dest.ColumnIndex].ColumnSpan = gcCalendarGrid.Content[source.Date].Rows[source.RowIndex].Cells[source.ColumnIndex].ColumnSpan;
// 元のセルを初期化します。
gcCalendarGrid.Content[source.Date].Rows[source.RowIndex].Cells[source.ColumnIndex].Value = null;
gcCalendarGrid.Content[source.Date].Rows[source.RowIndex].Cells[source.ColumnIndex].ColumnSpan = 1;
// 移動先のセルを現在のセルに設定します。
gcCalendarGrid.CurrentCellPosition = new CalendarCellPosition(dest.Date, dest.RowIndex, dest.ColumnIndex);
}
}
void gcCalendarGrid1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
旧文書番号
40734