Enos

Enos

  • NA
  • 140
  • 26.2k

How do I add a timestamp to a gridview

Feb 26 2015 8:10 AM

How do I add a timestamp to a gridview that shows the last time a row was edited? I've been searching Google but haven't found anything helpful yet.

I tried to create a method which will update the time when you edit or add a column. but i dont know how to take it further like parsing it to each and every column.

my table columns
 
 private DataTable GetDataTableFromDataGridview(DataGridView _grid)
    {
      {
            var _oDataTable = new DataTable();
            object[] cellValues = new object[_grid.Columns.Count];
             //clearTable();
            _oDataTable.Columns.Add("Name", typeof(string));
            _oDataTable.Columns.Add("Value", typeof(string));
            _oDataTable.Columns.Add("Font", typeof(string));
            _oDataTable.Columns.Add("DateStamp", typeof(string));
            _oDataTable.Columns.Add("Comment", typeof(string));
            foreach (DataGridViewRow row in _grid.Rows)
            {
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    cellValues[i] = row.Cells[i].Value;
                }
                _oDataTable.Rows.Add(cellValues.ToArray());
            }
            return _oDataTable;
        }

    }
 
 
private DateTime _dateTime; string _DateTimeFormat = "yyyy/dd/MM HH:mm:ss"; public void UpdateTheCurrentTime() {         _dateTime = DateTime.Now;         _dateTime.ToString(_DateTimeFormat, CultureInfo.InvariantCulture); }
 

Answers (1)