Here is the code show and load the meeting time data from start to finish time of each room. but don't know how to merge into 1 cell only from the meeting start time to the end meeting time as shown below, hope everyone can support
C#
private void selectAreaColor()
{
string starttime1 = cboStarttime.Text;
string stoptime1 = cboStoptime.Text;
// Get the start time and end time inputs and the selected meeting room
DateTime startTime = DateTime.ParseExact(starttime1, "HH:mm", null);
DateTime endTime = DateTime.ParseExact(stoptime1, "HH:mm", null);
string selectedRoom = cboRoom.SelectedItem.ToString();// You Can Use this Dynamic Based on Your Selection
// Loop through the rows in the DataGridView and find the matching row
foreach (DataGridViewRow row in grdMeeting.Rows)
{
if (row.Cells[0].Value.ToString() == selectedRoom)
{
int rowIndex = row.Index;
// Loop through the columns and compare the start and end times with the time slots
for (int i = 1; i < grdMeeting.Columns.Count; i++)
{
DateTime columnTime;
try
{
columnTime = DateTime.ParseExact(grdMeeting.Columns[i].HeaderText, "HH:mm", CultureInfo.InvariantCulture);
}
catch (Exception ex)
{
continue;
}
//DateTime columnTime = DateTime.ParseExact(grdMeeting.Columns[i].HeaderText, "HH:mm", null);
string _HeaderText = grdMeeting.Columns[i].Name.ToString();
if (startTime == columnTime)//|| endTime == columnTime
{
grdMeeting.Rows[rowIndex].Cells[_HeaderText].Style.BackColor = Color.Teal;
if (startTime == endTime)
return;
else
startTime = startTime.AddMinutes(30);
}
}
}
}
}

Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 6, 2023, 6:34 AM EDT
private void selectAreaColor() { string starttime1 = cboStarttime.Text; string stoptime1 = cboStoptime.Text; // Get the start time and end time inputs and the selected meeting room DateTime startTime = DateTime.ParseExact(starttime1, "HH:mm", null); DateTime endTime = DateTime.ParseExact(stoptime1, "HH:mm", null); string selectedRoom = cboRoom.SelectedItem.ToString();// You Can Use this Dynamic Based on Your Selection // Loop through the rows in the DataGridView and find the matching row foreach (DataGridViewRow row in grdMeeting.Rows) { if (row.Cells[0].Value.ToString() == selectedRoom) { int rowIndex = row.Index; int startColumnIndex = -1; int endColumnIndex = -1; bool inMeeting = false; // Loop through the columns and compare the start and end times with the time slots for (int i = 1; i = startTime && columnTime < endTime) { // If we are not already in a meeting, mark the start column if (!inMeeting) { startColumnIndex = i; inMeeting = true; } endColumnIndex = i; } } // Merge the cells if there is a meeting if (inMeeting) { DataGridViewCell startCell = grdMeeting.Rows[rowIndex].Cells[startColumnIndex]; DataGridViewCell endCell = grdMeeting.Rows[rowIndex].Cells[endColumnIndex]; int rowSpan = endColumnIndex - startColumnIndex + 1; startCell.RowSpan = rowSpan; for (int i = startColumnIndex + 1; i <= endColumnIndex; i++) { DataGridViewCell cell = grdMeeting.Rows[rowIndex].Cells[i]; cell.Visible = false; } } } } }