3
Answers

How to complete time format in datagridview cell in c#

Pavithra L

Pavithra L

9y
285
1
Hai,
 
I want to complete the time formate in datagridview cell . Here I can only type the time like this 1120a and after I click the tab it will complete the full formate like this 11:20 am if I can type 120p means it will complete the time as 01:20PM how can I do this. Please anybody help this .
 
Thanks in advance. 
Answers (3)
0
Vulpes

Vulpes

NA 98.3k 1.5m 10y
Assuming all numeric columns are of type double, then try:

   foreach(DataRow dr in table1.Rows)
   {
      string colName = dr["Par Name"].ToString();
      if(table5.Columns.Contains(colName))
      {
         double lower = (double)dr["lower_limit"];
         double upper = (double)dr["upper_limit"];
         double min = table5.Rows.Cast<DataRow>().Min(r => r.Field<double>(colName));
             
         if (min >= lower)
         {
            double max = table5.Rows.Cast<DataRow>().Max(r => r.Field<double>(colName));
            if (max <= upper) table5.Columns.Remove(colName);
         }
      }
   }

or, if they're all strings, try:

   foreach(DataRow dr in table1.Rows)
   {
      string colName = dr["Par Name"].ToString();
      if(table5.Columns.Contains(colName))
      {
         double lower = double.Parse(dr["lower_limit"].ToString());
         double upper = double.Parse(dr["upper_limit"].ToString());
         double min = table5.Rows.Cast<DataRow>().Min(r => double.Parse(r.Field<string>(colName)));
             
         if (min >= lower)
         {
            double max = table5.Rows.Cast<DataRow>().Max(r => double.Parse(r.Field<string>(colName)));
            if (max <= upper) table5.Columns.Remove(colName);
         }
      }
   }

Accepted
0
Farhan Shariff

Farhan Shariff

NA 1.1k 111.4k 10y
Thank you vulpes . works perfect only  thing is I had to remove the last three columns from table5 (Split , Die_id and normal inverse), since I am adding it later again no problem :)
0
Khan Abrar Ahmed

Khan Abrar Ahmed

NA 5.8k 200k 10y
Hi,
what basis u want to match the rows?? please explain little bit more.