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[] { '\n' });
string date = list[0];
DateTime placedDate;
if (DateTime.TryParse(date, out placedDate))
{
MessageBox.Show("Placed Date:" + placedDate.ToShortDateString());
}
}
} |
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
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[] { '\n' });
string date = list[0];
DateTime placedDate;
if (DateTime.TryParse(date, out placedDate))
{
MessageBox.Show("Placed Date:" + placedDate.ToShortDateString());
}
}
} |
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[] { '\n' });
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;
} |