Archive

Posts Tagged ‘formatting’

Change cell formatting on DataGridView

June 4th, 2009 wiley No comments

How to change the visual presentation of the scope of DataGridView. If in a particular field of the table in the database have such a unix timestamp value like visualizing it as a standard date and time. Add EventHandler CellFormating for the DataGridView.

private void dgvActiveUsers_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
  try
  {
    if (dgvActiveUsers.Columns[e.ColumnIndex].Name.Equals("logindate"))
    {
      DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
      e.Value = origin.AddSeconds(double.Parse(e.Value.ToString())).ToShortDateString() + " - " + origin.AddSeconds(double.Parse(e.Value.ToString())).ToShortTimeString();
     }
   }
   catch (Exception)
   {
   }
}

This method can give an idea and many other types of formatting values.


Unique visitors to post: 5

Categories: C# Tags: , ,
Google Analytics integration offered by Wordpress Google Analytics Plugin