Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6964171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:53:27+00:00 2026-05-27T15:53:27+00:00

I load an XML file, I transfer the data to the dataset and I

  • 0

I load an XML file, I transfer the data to the dataset and I display with the datagridview1.

I have 3 colums: start, end, and status.

The format of column start is datetime like 8:00 AM

The format of column end is datetime too like 10:00 PM

Status is two values: ok or nok.

I need to compare the datetime system with the start column and the end column, if the date system are between the two value, I display ok in the row. I need to do that for each row. for ok I need to change the background color to green and nok will be red.
could you help me? …. I m lost between the dataset and the datagridview.
thanks a lot

Thank you guys for your help : I modified a little the code, given by you 🙂

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Globalization;
using System.Security.Permissions;


namespace tab
{
    public partial class Form1 : Form
    {
        public Form1()
        {
        InitializeComponent();
        DataSet ds = new DataSet(); 
        ds.ReadXml("C:\\Sites.xml"); 
        int count = 0; 
        foreach (DataRow dr in ds.Tables[0].Rows) 
        { 


            string s1 = dr[0].ToString();
            string s2 = dr[1].ToString();
            string timeSys = DateTime.Now.ToString("hh:mm tt");
            TimeSpan Start = DateTime.ParseExact(s1, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; 
            TimeSpan End = DateTime.ParseExact(s2, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay;
            TimeSpan Now = DateTime.ParseExact(timeSys, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay;

            if (Start.Hours < Now.Hours && Now.Hours < End.Hours) 
            { 
               ds.Tables[0].Rows[count][2] = "OK"; 

            } 
            else 
            { 
                ds.Tables[0].Rows[count][2] = "NOK"; 
            } 
            count++; 
        }

        dataGridView1.DataSource = ds.Tables[0];

        for (int icount = 0; icount < dataGridView1.RowCount-1; icount++) 
        { 
            DataGridViewRow theRow = dataGridView1.Rows[icount]; 

            if (theRow.Cells[2].Value.ToString() == "OK") 

                theRow.Cells[2].Style.BackColor = Color.Green; 
            else 

                theRow.Cells[2].Style.BackColor = Color.Red; 
        }

    } 

        }
    }

I have still an issue, I didn’t see the color displayed in the datagridview.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:53:28+00:00Added an answer on May 27, 2026 at 3:53 pm
           DataSet ds = new DataSet();
            ds.ReadXml(@"...\\..\\Sites.xml");
            int count = 0;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
    
    
                string s1 = dr[0].ToString(); 
                string s2 = dr[1].ToString();
                TimeSpan ts1 = DateTime.ParseExact(s1, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay;
                TimeSpan ts2 = DateTime.ParseExact(s2, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay;
                TimeSpan now = DateTime.Now.TimeOfDay;
    
                if (ts1.Hours >= 8 && ts2.Hours <= 22)
                {
                   ds.Tables[0].Rows[count][2] = "OK";
    
                }
                else
                {
                    ds.Tables[0].Rows[count][2] = "NOK";
                }
                count++;
            }
    
            grdvw_wnfrm.DataSource = ds.Tables[0];
    
            for (int icount = 0; icount < grdvw_wnfrm.RowCount-1; icount++)
            {
                DataGridViewRow theRow = grdvw_wnfrm.Rows[icount];
    
                if (theRow.Cells[2].Value.ToString() == "OK")
    
                    theRow.Cells[2].Style.BackColor = Color.Green;
                else
    
                    theRow.Cells[2].Style.BackColor = Color.Red;
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used DataSet to load a schema from following xml file; <node id=0> <node
I want to modify an existing XML-File. I used a DataSet to load the
I have a page that is using jQuery to load an XML file, which
I'm trying to use the following code # LOAD XML FILE $XML = new
I need to load a .xml file from a URL adress into an NSData
I am trying to load an xml file that is stored as a resource
I'm looking for a way to load an XML file's contents directly into a
I'm trying to load a simple Xml file (encoded in UTF-8): <?xml version=1.0 encoding=UTF-8?>
I need to modify a (xml-)file from Apache Ant. loadfile task allows to load
I want to load key/values configuration pairs stored in XML file. To bind a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.