Jump to content

Error load meeting and time to datagridview


Recommended Posts

I have 2 table on api data: 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 }

After booking and save the meeting room, the data will be submitted to the Booking table. on form i create datagridview to view

meeting schedule and meeting room get the list of rooms in the Room api table and add new hour columns

add a new column that is the time and get the data to browse the Booking table to compare the start time and end time of the meeting

like code and picture. convert columns header is hour to compare and get the time range and load the color to know which room is meeting at which time

in the load event call the function: selectAreaColor() then got an error, but the load function does not call and book the room,

it can run and get the results as shown, but when starting to run and the load function calls, the error hope everyone can help, thanks a lot.

when adding new run debug, it browses from column header at 08:00 to the end of column and booking table data runs ok and the load event, it browses the data from the booking table to the columns on the datagridview, so it crashes

here is the code to get the display area of meeting time and meeting schedule

private 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);//event load here error

string _HeaderText = grdRoom.Columns[i].Name.ToString();

if (startTime == columnTime)//|| endTime == columnTime


grdRoom.Rows[rowIndex].Cells[_HeaderText].Style.BackColor = Color.Blue;

if (startTime == stopTime)



startTime = startTime.AddMinutes(30);








Link to comment
Share on other sites

  • 3 months later...

The error is probably because of the date format.

Try with this:


DateTime columnTime;
    columnTime = DateTime.ParseExact(grdRoom.Columns[i].HeaderText, "HH:mm", CultureInfo.InvariantCulture);
catch (FormatException ex)
    MessageBox.Show($"Error parsing date/time from column header: {ex.Message}");


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...