I have four columns my program populates at run time from database. One of the column is a date data. I converted those dates to string when populating but when it comes to sort this column it can't work with strings (obviously 10-23-2007 will be considered as before 11-23-2002).
How do I create a list view that can be sorted by date field. I also would like users to click on the column heading to sort by the date field. Is listView not a good choice for this?
public void ReadGradeData()
{
try
{
using (SqlConnection scn = new SqlConnection(cs))
{
string sp = "up_ViewGrade";
SqlDataReader rdr = null;
SqlCommand spcmd = new SqlCommand(sp, scn);
spcmd.CommandType = CommandType.StoredProcedure;
scn.Open();
rdr = spcmd.ExecuteReader();
while (rdr.Read())
{
// get the results of each column
GradeDate = (DateTime)rdr["RECORD_ID"];
strSystem = (string)rdr["System"];
strLocation = (string)rdr["Location"];
strGrade = (string)rdr["Sensor_ID"];
lstGrade.View = View.Details;
//*********
ListViewItem item = new ListViewItem(new[] { Convert.ToString(GradeDate), strGrade, strSystem, strLocation });
lstGrade.Items.Add(item);
//*********
}
}
}