I have 4 api data tables: Booking{ Id, Status, Sort, CreatedDate,UpdatedAt, Title, ParticipatingLeaders, Content, UserCreatedName, UserCreatedEmail, UserCreatedPhoneNumber, DepartmentId, Start, Stop, LocationId, Request,RoomId, Date, CancelAt, SuccessAt,HostUser, LocationName, RoomName }
Room{ Id, Status, Sort, CreatedDate, CreatedAt, UpdatedAt, UpdatedBy, CodeNaame, Name, LocationId, Volumn, Items, Images }
Location{ Id, Status, Sort, CreatedDate, CreatedAt, CreatedBy, UpdatedAt, UpdatedBy, Title }
Device{ Id, Status, Sort, CreatedDate, CreatedAt, CreatedBy, UpdatedAt, UpdatedBy, Name, Description, Content }.
After booking the meeting room, the data will be submitted to the Booking table. on datagridview i create grid to view meeting schedule and meeting room get the list of rooms in the Room api table and add new hour columns like code and picture. in the load event call the function: selectAreaColor() then got an error that couldn't load meeting room time data

private void loaddataRoom()//load room
{
try
{
QueryRQ query = CreateQuery();
RoomIndexRS result = apiBooking.getRoom(query).Result;
if (result == null)
{
MessageBox.Show("Không l?y du?c k?t qu? t? phía server", Program.Setting.Language.GetString("captionerror"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else if (result.Status != 200)
{
MessageBox.Show(result.Error, Program.Setting.Language.GetString("captionerror"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
grdRoom.DataSource = result.Data;
string columns = "name";
string[] _arrColumns = columns.Split(',');
grdRoom.Columns["name"].Width = 152;
foreach (DataGridViewColumn col in grdRoom.Columns)
{
if (_arrColumns.Contains(col.Name.ToLower()))
{
col.DisplayIndex = _arrColumns.ToList().LastIndexOf(col.Name.ToLower());
col.HeaderText = Program.Setting.Language.GetString("colgrd" + col.Name);
col.Resizable = DataGridViewTriState.True;
}
else
{
col.Visible = false;
}
}
//// Create a new column,DataGridViewTextBoxColumn external declare
column1Room = new DataGridViewTextBoxColumn();
column1Room.HeaderText = "08:00"; // Set the header text
column1Room.Name = "column1"; // Set the name of the column
column1Room.Width = 55;
// Add the column to the DataGridView
grdRoom.Columns.Add(column1Room);
column2Room = new DataGridViewTextBoxColumn();
column2Room.HeaderText = "08:30"; // Set the header text
column2Room.Name = "column2"; // Set the name of the column
column2Room.Width = 55;
grdRoom.Columns.Add(column2Room);
column3Room = new DataGridViewTextBoxColumn();
column3Room.HeaderText = "09:00"; // Set the header text
column3Room.Name = "column3"; // Set the name of the column
column3Room.Width = 55;
grdRoom.Columns.Add(column3Room);
//column3Room.DefaultCellStyle.BackColor = Color.Plum;
column4Room = new DataGridViewTextBoxColumn();
column4Room.HeaderText = "09:30"; // Set the header text
column4Room.Name = "column4"; // Set the name of the column
column4Room.Width = 55;
grdRoom.Columns.Add(column4Room);
column5Room = new DataGridViewTextBoxColumn();
column5Room.HeaderText = "10:00"; // Set the header text
column5Room.Name = "column5"; // Set the name of the column
column5Room.Width = 55;
grdRoom.Columns.Add(column5Room);
column6Room = new DataGridViewTextBoxColumn();
column6Room.HeaderText = "10:30"; // Set the header text
column6Room.Name = "column6"; // Set the name of the column
column6Room.Width = 55;
grdRoom.Columns.Add(column6Room);
column7Room = new DataGridViewTextBoxColumn();
column7Room.HeaderText = "11:00"; // Set the header text
column7Room.Name = "column7"; // Set the name of the column
column7Room.Width = 55;
grdRoom.Columns.Add(column7Room);
column8Room = new DataGridViewTextBoxColumn();
column8Room.HeaderText = "11:30"; // Set the header text
column8Room.Name = "column8"; // Set the name of the column
column8Room.Width = 55;
grdRoom.Columns.Add(column8Room);
column9Room = new DataGridViewTextBoxColumn();
column9Room.HeaderText = "12:00"; // Set the header text
column9Room.Name = "column9"; // Set the name of the column
column9Room.Width = 55;
grdRoom.Columns.Add(column9Room);
column10Room = new DataGridViewTextBoxColumn();
column10Room.HeaderText = "12:30"; // Set the header text
column10Room.Name = "column10"; // Set the name of the column
column10Room.Width = 55;
grdRoom.Columns.Add(column10Room);
column11Room = new DataGridViewTextBoxColumn();
column11Room.HeaderText = "13:00"; // Set the header text
column11Room.Name = "column11"; // Set the name of the column
column11Room.Width = 55;
grdRoom.Columns.Add(column11Room);
column12Room = new DataGridViewTextBoxColumn();
column12Room.HeaderText = "13:30"; // Set the header text
column12Room.Name = "column12"; // Set the name of the columng
column12Room.Width = 55;
grdRoom.Columns.Add(column12Room);
column13Room = new DataGridViewTextBoxColumn();
column13Room.HeaderText = "14:00"; // Set the header text
column13Room.Name = "column13"; // Set the name of the column
column13Room.Width = 55;
grdRoom.Columns.Add(column13Room);
column14Room = new DataGridViewTextBoxColumn();
column14Room.HeaderText = "14:30"; // Set the header text
column14Room.Name = "column14"; // Set the name of the column
column14Room.Width = 55;
grdRoom.Columns.Add(column14Room);
column15Room = new DataGridViewTextBoxColumn();
column15Room.HeaderText = "15:00"; // Set the header text
column15Room.Name = "column15"; // Set the name of the column
column15Room.Width = 55;
grdRoom.Columns.Add(column15Room);
column16Room = new DataGridViewTextBoxColumn();
column16Room.HeaderText = "15:30"; // Set the header text
column16Room.Name = "column16"; // Set the name of the column
column16Room.Width = 52;
grdRoom.Columns.Add(column16Room);
column17Room = new DataGridViewTextBoxColumn();
column17Room.HeaderText = "16:00"; // Set the header text
column17Room.Name = "column17"; // Set the name of the column
column17Room.Width = 52;
grdRoom.Columns.Add(column17Room);
column18Room = new DataGridViewTextBoxColumn();
column18Room.HeaderText = "16:30"; // Set the header text
column18Room.Name = "column18"; // Set the name of the column
column18Room.Width = 52;
grdRoom.Columns.Add(column18Room);
column19Room = new DataGridViewTextBoxColumn();
column19Room.HeaderText = "17:00"; // Set the header text
column19Room.Name = "column19"; // Set the name of the column
column19Room.Width = 52;
grdRoom.Columns.Add(column19Room);
column20Room = new DataGridViewTextBoxColumn();
column20Room.HeaderText = "17:30"; // Set the header text
column20Room.Name = "column20"; // Set the name of the column
column20Room.Width = 52;
grdRoom.Columns.Add(column20Room);
column21Room = new DataGridViewTextBoxColumn();
column21Room.HeaderText = "18:00"; // Set the header text
column21Room.Name = "column21"; // Set the name of the column
// column21Room.Width = 52;
grdRoom.Columns.Add(column21Room);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//here code to get data on demand
private async void selectAreaColor()
{
string starttime ;
string stoptime ;
string selectedRoom ;
string selectedId ;
QueryRQ query = CreateQuery();
BookingIndexRS result = apiBooking.getBooking(query).Result;
foreach (BookingDetail r in result.Data)
{
string idLocal = r.Id.ToString();
selectedId = idLocal + "";
string idroom = r.RoomId.ToString();
selectedRoom = idroom + "";
string start = r.Start.ToString();
starttime = start;
string stop = r.Stop.ToString();
stoptime = stop;
string getDate =(r.Date.ToString());
// Get the start time and end time inputs and the selected meeting room
DateTime startTime = DateTime.ParseExact(starttime, "HH:mm", null);
DateTime stopTime = DateTime.ParseExact(stoptime, "HH:mm", null);
foreach (DataGridViewRow row in grdRoom.Rows)
{
if (row.Cells["Id"].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 < grdRoom.Columns.Count; i++)
{
DateTime columnTime = DateTime.ParseExact(grdRoom.Columns[i].HeaderText, "HH:mm",CultureInfo.InvariantCulture);//error here
string _HeaderText = grdRoom.Columns[i].Name.ToString();
if (startTime == columnTime)//|| endTime == columnTime
{
grdRoom.Rows[rowIndex].Cells[_HeaderText].Style.BackColor = Color.Blue;
if (startTime == stopTime)
return;
else
startTime = startTime.AddMinutes(30);
}
}
}
}
}
}
error line 202 it' loop through on BookingDetail. but i need loop through grdRoom