This is a migrated thread and some comments may be shown as answers.

Drag and Drop from rad grid with non-ienumerable data

2 Answers 53 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 04 Jun 2014, 04:46 PM
Hi,

Let me first start by saying I like your controls and products. I am implementing a RadGrid and Scheduler with the idea of dragging and dropping rows from the grid and placing them on the scheduler. I am using the following demo as a guideline: 
http://demos.telerik.com/aspnet-ajax/scheduler/examples/draganddropintegration/defaultcs.aspx?product=scheduler

The issue I am having is that in your example you are filling the rad grid with task data whose data table has an ID column with an int data type. When you drop the row over the grid it appears to use that integer ID field as the appointment id and places a new appointment in the index.

Like this: 
protected void RadGrid1_RowDrop(object sender, GridDragDropEventArgs e)
        {
            GridDataItem dataItem = e.DraggedItems[0];
 
            Hashtable values = new Hashtable();
            dataItem.ExtractValues(values);
            (int)dataItem.GetDataKeyValue("ID");
            string firstName = (string)values["FirstName"];
            string lastName = (string)values["LastName"];
            string targetSlotIndex = TargetSlotHiddenField.Value;
 
            if (targetSlotIndex != string.Empty)
            {
                HandleSchedulerDrop(id, firstName, targetSlotIndex);
                TargetSlotHiddenField.Value = string.Empty;
            }
            RadScheduler1.Rebind();
            rgGridViewUsers.Rebind();
             
            RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, RadScheduler1);
        }
 
 
        private void HandleSchedulerDrop(int id, string subject, string targetSlotIndex)
        {
            RadScheduler1.Rebind();
 
            ISchedulerTimeSlot slot = RadScheduler1.GetTimeSlotFromIndex(targetSlotIndex);
 
            TimeSpan duration = TimeSpan.FromHours(1);
            if (slot.Duration == TimeSpan.FromDays(1))
            {
                duration = slot.Duration;
            }
 
            ScheduleAppointment(id, subject, slot.Start, slot.Start.Add(duration));
        }
 
 private void ScheduleAppointment(int id, string subject, DateTime start, DateTime end)
        {
            IDataSource dataSource = SchedulerDataSource;
            DataSourceView view = dataSource.GetView("DefaultView");
 
            IOrderedDictionary data = new OrderedDictionary();
            data.Add("Subject", subject);
            data.Add("Start", start);
            data.Add("End", end);
 
            IDictionary keys = new OrderedDictionary();
            keys.Add("ID", id);
            //keys.Add("ID", 234);
 
            view.Update(keys, data, new OrderedDictionary(), OnDataSourceOperationComplete);
        }
 
        private static bool OnDataSourceOperationComplete(int count, Exception e)
        {
            if (e != null)
            {
                throw e;
            }
            return true;
        }


However I am trying to add a list of users to the list where the ID column is unique identifier (Guid). After I dropping the even on the scheduler everything seems to work fine up until I get to the the callback OnDataSourceOperationComplete(), where i get an error stating that the key must be of the ienumerbale type.

Here is my code again with the int datatype changed to Guid:
protected void RadGrid1_RowDrop(object sender, GridDragDropEventArgs e)
       {
           GridDataItem dataItem = e.DraggedItems[0];
 
           Hashtable values = new Hashtable();
           dataItem.ExtractValues(values);
            
           Guid id = new Guid((string)values["ID"]);//(int)dataItem.GetDataKeyValue("ID");
           string firstName = (string)values["FirstName"];
           string lastName = (string)values["LastName"];
           string targetSlotIndex = TargetSlotHiddenField.Value;
 
           if (targetSlotIndex != string.Empty)
           {
               HandleSchedulerDrop(id, firstName, targetSlotIndex);
               TargetSlotHiddenField.Value = string.Empty;
           }
           RadScheduler1.Rebind();
           rgGridViewUsers.Rebind();
            
           RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, RadScheduler1);
       }
 
 
       private void HandleSchedulerDrop(Guid id, string subject, string targetSlotIndex)
       {
           RadScheduler1.Rebind();
 
           ISchedulerTimeSlot slot = RadScheduler1.GetTimeSlotFromIndex(targetSlotIndex);
 
           TimeSpan duration = TimeSpan.FromHours(1);
           if (slot.Duration == TimeSpan.FromDays(1))
           {
               duration = slot.Duration;
           }
 
           ScheduleAppointment(id, subject, slot.Start, slot.Start.Add(duration));
       }
 
 
private void ScheduleAppointment(Guid id, string subject, DateTime start, DateTime end)
       {
           IDataSource dataSource = SchedulerDataSource;
           DataSourceView view = dataSource.GetView("DefaultView");
 
           IOrderedDictionary data = new OrderedDictionary();
           data.Add("Subject", subject);
           data.Add("Start", start);
           data.Add("End", end);
 
           IDictionary keys = new OrderedDictionary();
           keys.Add("ID", id);
           //keys.Add("ID", 234);
 
           view.Update(keys, data, new OrderedDictionary(), OnDataSourceOperationComplete);
       }
 
       private static bool OnDataSourceOperationComplete(int count, Exception e)
       {
           if (e != null)
           {
               throw e;
           }
           return true;
       }

Unfortunately I am not sure how to overcome this.

Can you provide an example perhaps of how to drag and drop items that have a non integer ID column data type? Or if this is even possible?

Thanks,
-Justin

2 Answers, 1 is accepted

Sort by
0
Justin
Top achievements
Rank 1
answered on 04 Jun 2014, 04:51 PM
I convertible not Ienumerable sorry about that one.
0
Boyan Dimitrov
Telerik team
answered on 09 Jun 2014, 01:42 PM
Hello,

Please find here how you can use GUID for an appointment id value instead of int value. In this case in the RadGrid RowDrop you can simply create an appointment object and add it to the appointment collection.


Regards,
Boyan Dimitrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Scheduler
Asked by
Justin
Top achievements
Rank 1
Answers by
Justin
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or