Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto map time and room to datagridview C#

Status
Not open for further replies.

hoangluc19

Programmer
Nov 18, 2019
10
VN
I want to look at the datagridview to know what time of the meeting is as shown in the picture. after selecting the start time and end time and choose the room
will automatically fill in the datagridview and have the background as shown. but the following code does not get that position, hope everyone can help.

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();

// 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)
{
// 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 = DateTime.ParseExact(grdMeeting.Columns.HeaderText, "HH:mm", null);
if (startTime == columnTime || endTime == columnTime)
{
//MessageBox.Show("Are you OK ");

grdMeeting.CurrentCell.Style.BackColor = Color.Blue;//Can't get the location to create the background
return;
}

}

}

}

hen_zl4nom.png
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top