Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to retrieve a Date value from a date-field-type-cell on a Datagridview and compare it with the current system time?

$
0
0

I have two date collumns on my DGV, one is Data (date) and the other is DataRemarcada(RescheduledDate), this form will be used for editing purposes, however, if a row containing both of these two date collums with  date values that are older tham the current system date, all the cells of the row must become read-only, and if possible, i want the background color of the cell to become gray or some disabled-like color :D

However i have no idea on how i can convert an object value (the datevalue of the cell) to a DateTime value and compare it with the current system date.

This is a little code i've tried to make, its raised by the DataBindingComplete event.

 

privatevoid dataGridAtualizar_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {// created a variable to store the current system date
            DateTime hoje = System.DateTime.Today;// for every row i have on the Datagridview...for (int i = 0; i < dataGridAtualizar.Rows.Count; i++)
            {//... i set the data(date, in english) variable value to the one on the Data cell
                DateTime data = dataGridAtualizar.Rows[i].Cells["Data"].Value;// ... i set the dataremarcada(RescheduledDate, in english) variable value to the one on the DataRemarcada cell
                DateTime dataremarcada = dataGridAtualizar.Rows[i].Cells["DataRemarcada"].Value;// if both of the Data and DataRemarcada values are dates older them the current system dateif (data > hoje && dataremarcada > hoje)
                {// For every collum with rows that matched the checks up there....for (int j = 0; j < dataGridAtualizar.Columns.Count; j++)
                    {// .. i set the row cells read-only property to true :D
                        dataGridAtualizar.Rows[i].Cells[j].ReadOnly = true;// Also i want to change the style/color of the cell backgroud// to gray color or something like that. 
                    }
                }
            }
        }


Here is a little screeshot to explain better:

http://i55.tinypic.com/2hqh5hw.png

 

Any help would be appreciated :D


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>