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. Image for the cookie policy date

Get DateTime from event DragDrop Schedule Control

Hello, 
How can I get the DateTime in the DragDrop event when I drop a data on the Schedule control to add an event with its StartTime? with this code

private void scheduleControl1_DragDrop(object sender, DragEventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int rowIndexOfItemUnderMouseToDrop;
                if (e.Effect == DragDropEffects.Copy)
                {
DataGridViewRow rowToMove = e.Data.GetData(typeof(DataGridViewRow)) as DataGridViewRow;
                    Console.WriteLine("test1: "+rowToMove.Cells[0].Value.ToString());


                    Point scPoint = scheduleControl1.PointToClient(new Point(e.X, e.Y));
                    
                }
            }
        }

Thanks.

7 Replies

DY Deivaselvan Y Syncfusion Team April 11, 2019 12:27 PM UTC

Hi Bosco, 

Thanks for using Syncfusion product. 

To get the date based on mouse point, you could use the PointToRowCol method to get the row and column index then you could get that cell value from ScheduleGrid using CellValue property. Please refer the following code example. 

C# 
int row, col; 
ScheduleGrid grid = (sender as ScheduleGrid); 
grid.PointToRowCol(e.Location, out row, out col); 
GridRangeInfo range1; 
if (grid.CoveredRanges.Find(row, col, out range1)) 
{ 
    row = range1.Top; 
} 
if (row > -1 && col > -1) 
{ 
    var cellValue = grid[row, col].CellValue; 
    if (cellValue != null) 
    { 
        string[] list = cellValue.ToString().Split(new char[] { '' }); 
        string date = list[0]; 
        DateTime placedDate; 
        if (DateTime.TryParse(date, out placedDate)) 
        { 
            MessageBox.Show("Placed Date:" + placedDate.ToShortDateString()); 
        } 
    } 
} 
 
Please get back to us if you need any further assistance on this.  

Regards,
Deivaselvan 



BH Bosco Hidalgo April 16, 2019 06:14 AM UTC

Hello, Thanks for all, but "e.Location" gives me an error and I can not get the date and time of the grid on which I made the drop, could you give me another way to develop it?
Thank you so much for everything


SR Sabaridass Ramamoorthy Syncfusion Team April 17, 2019 09:01 AM UTC

Hi Bosco,  
 
If you are unable to get the e.Location value from DragDrop event, you could use the Cursor.Position and PointToClient method. Please refer the following code example. 
 
C# 
int row, col; 
ScheduleGrid grid = (sender as ScheduleGrid); 
Point mousePosition = Cursor.Position; 
Point location = grid.PointToClient(mousePosition); 
grid.PointToRowCol(location, out row, out col); 
GridRangeInfo range1; 
if (grid.CoveredRanges.Find(row, col, out range1)) 
{ 
    row = range1.Top; 
} 
if (row > -1 && col > -1) 
{ 
    var cellValue = grid[row, col].CellValue; 
    if (cellValue != null) 
    { 
        string[] list = cellValue.ToString().Split(new char[] { '' }); 
        string date = list[0]; 
        DateTime placedDate; 
        if (DateTime.TryParse(date, out placedDate)) 
        { 
            MessageBox.Show("Placed Date:" + placedDate.ToShortDateString()); 
        } 
    } 
} 
 
Please get back to us if you need any further assistance on this. 
 
Regards, 
Sabaridass R 
 



BH Bosco Hidalgo April 17, 2019 10:39 AM UTC

Thanks, but now have other error, grid return null

ScheduleGrid grid = (sender as ScheduleGrid); 


do you know?

Thanks.



MG Mohanraj Gunasekaran Syncfusion Team April 18, 2019 08:10 AM UTC

Hi Bosco, 

Thanks for your update. 

If you are trying the provided code part in SchedulGrid.DragDrop event, you could get the ScheduleGrid in sender. So, please let us know, in which event are you trying this code. And, please provide the what object type are you getting in sender. Please provide this kind of information it will be helpful us to provide the solution at the earliest. 

Regards, 
Mohanraj G 



BH Bosco Hidalgo April 22, 2019 01:02 PM UTC


hello, it is already working but only returns the date / time if we are in week or month, but it does not work if we are in day or week of work, the cellvalue returns it to me empty.

would you tell me why?

Thanks.


SR Sabaridass Ramamoorthy Syncfusion Team April 23, 2019 12:14 PM UTC

Hi Bosco, 

Thanks for your update. 

To get the Date from DragDrop event for day and work week view, you could make use of the following code example. 

C# 
private void Form1_DragDrop(object sender, DragEventArgs e) 
{ 
    int row, col; 
    ScheduleGrid grid = (sender as ScheduleGrid); 
    grid.PointToRowCol(new Point(e.X,e.Y), out row, out col); 
    GridRangeInfo range1; 
    if (grid.CoveredRanges.Find(row, col, out range1)) 
    { 
        row = range1.Top; 
    } 
    if (row > -1 && col > -1) 
    { 
        if (this.scheduleControl1.ScheduleType == ScheduleViewType.Day) 
        { 
            string time = GetTimeDisplayText(row); 
            int i = time.IndexOf('|'); 
            if (i > 0) 
            { 
                time = time.Substring(0, i); 
            } 
            string text = time; 
            DateTime currentDate = this.scheduleControl1.Calendar.DateValue; 
            DateTime dropTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, currentDate.Hour, currentDate.Minute, currentDate.Second); 
        } 
        else if (this.scheduleControl1.ScheduleType == ScheduleViewType.WorkWeek || this.scheduleControl1.ScheduleType == ScheduleViewType.CustomWeek) 
        { 
            int num = grid.ColCount / this.scheduleControl1.Calendar.SelectedDates.Count; 
            int pos = col / num; 
            DateTime dropPosition = this.scheduleControl1.Calendar.SelectedDates[pos - 2]; 
        } 
        else 
        { 
            var cellValue = grid[row, col].CellValue; 
            if (cellValue != null) 
            { 
                string[] list = cellValue.ToString().Split(new char[] { '' }); 
                string date = list[0]; 
                DateTime placedDate; 
                if (DateTime.TryParse(date, out placedDate)) 
                { 
                     
                } 
            } 
        } 
    } 
} 
 
private string GetTimeDisplayText(int rowIndex) 
{ 
    int val = RowIndexTo24Time(rowIndex); 
    string amPm = val < 12 ? "|" + scheduleControl1.Culture.DateTimeFormat.AMDesignator : "|" + scheduleControl1.Culture.DateTimeFormat.PMDesignator; 
    if (this.scheduleControl1.Appearance.Hours24 || this.scheduleControl1.Culture.DateTimeFormat.AMDesignator == string.Empty) 
    { 
        return val.ToString() + "|00"; 
    } 
    else 
    { 
        val = val % 12; 
        if (val == 0) 
        { 
            val = 12; 
        } 
 
        return val.ToString() + amPm; 
    } 
} 
 
private int RowIndexTo24Time(int rowIndex) 
{ 
    return (rowIndex - 5) / this.scheduleControl1.Appearance.DivisionsPerHour; 
} 
 
Please get back to us if you need any further assistance on this. 

Regards, 
Sabaridass R 


Loader.
Live Chat Icon For mobile
Up arrow icon