The Drag & Drop service is working perfectly on my RadGridView until I add a GridViewTemplate to it with the intent to create a hierarchy view, after which the drag events aren't even fired anymore. Any ideas, please?
This is how I initialize the Drag & Drop behavior on my main DataGrid:
private void InitGrid()
{
bt_addAttachment.Visible = false;
BaseGridBehavior gridBehavior = this.radGridView1.GridBehavior as BaseGridBehavior;
gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new CustomRowGridBehavior());
//handle drag and drop events for the grid through the DragDrop service
RadDragDropService svc = this.radGridView1.GridViewElement.GetService<RadDragDropService>();
svc.PreviewDragStart += svc_PreviewDragStart;
svc.PreviewDragDrop += svc_PreviewDragDrop;
svc.PreviewDragOver += svc_PreviewDragOver;
}
//required to initiate drag and drop when grid is in bound mode
private void svc_PreviewDragStart(object sender, PreviewDragStartEventArgs e)
{
e.CanStart = true;
}
private void svc_PreviewDragOver(object sender, RadDragOverEventArgs e)
{
if (e.DragInstance is GridDataRowElement)
{
e.CanDrop = e.HitTarget is SchedulerCellElement;
}
}
private void svc_PreviewDragDrop(object sender, RadDropEventArgs e)
{
SchedulerCellElement schedulerCell = e.HitTarget as SchedulerCellElement;
if (schedulerCell == null)
{
//DayViewAllDayHeader allDay = (this.radScheduler1.SchedulerElement.ViewElement as SchedulerDayViewElement).AllDayHeaderElement;
//schedulerCell = SchedulerUIHelper.GetCellAtPoint(e.DropLocation, allDay.Children);
}
if (schedulerCell == null)
{
return;
}
GridDataRowElement draggedRow = e.DragInstance as GridDataRowElement;
if (draggedRow == null)
{
return;
}
DataRowView dataRowView = draggedRow.Data.DataBoundItem as DataRowView;
if (dataRowView != null)
{
if (draggedRow.GridControl.DataSource != null && typeof(BindingSource).IsAssignableFrom(draggedRow.GridControl.DataSource.GetType()))
{
Appointment appointment = new Appointment();
appointment.Start = (DateTime)draggedRow.RowInfo.Cells["Start"].Value;
appointment.End = (DateTime)draggedRow.RowInfo.Cells["End"].Value;
//adjust start/end according to target cell
appointment.End = schedulerCell.Date.AddMinutes(appointment.Duration.TotalMinutes);
appointment.Start = schedulerCell.Date;
appointment.Summary = string.Empty + draggedRow.RowInfo.Cells["Summary"].Value;
appointment.Description = string.Empty + draggedRow.RowInfo.Cells["Description"].Value;
appointment.Location = string.Empty + draggedRow.RowInfo.Cells["Location"].Value;
appointment.StatusId = (int)draggedRow.RowInfo.Cells["StatusId"].Value;
appointment.BackgroundId = (int)draggedRow.RowInfo.Cells["BackgroundId"].Value;
//this.radScheduler1.Appointments.Add(appointment);
dataRowView.Row.Table.Rows.Remove(dataRowView.Row);
}
else
{
throw new ApplicationException("Unhandled Scenario");
}
}
}
Which is working perfectly until I add this piece of code to it:
///attachments sub-row initialization
GridViewTemplate attachmentsTemplate = new GridViewTemplate();
attachmentsTemplate.AutoGenerateColumns = false;
attachmentsTemplate.HierarchyDataProvider = new GridViewEventDataProvider(attachmentsTemplate);
GridViewTextBoxColumn columnMainJobID = new GridViewTextBoxColumn();
columnMainJobID.TextAlignment = ContentAlignment.MiddleCenter;
columnMainJobID.FieldName = "MainJobID";
columnMainJobID.IsVisible = false;
attachmentsTemplate.Columns.Add(columnMainJobID);
radGridView1.Templates.Add(attachmentsTemplate);