I haver this piece of code. which is giving me a nullreferenceexception..
private void dgvMessages_SelectionChanged(object sender, EventArgs e)
{
if (dgvMessages.CurrentRow == null)
{
return;
}
try
{
int select = dgvMessages.CurrentRow.Index; //NULL REFERENCE EXCEPTION
DateTime dateTimeMessage = Convert.ToDateTime(dgvMessages.Rows[select].Cells[1].Value.ToString());
string date = dateTimeMessage.ToLongDateString();
string time = dateTimeMessage.ToLongTimeString();
lblDate.Text = "Date: " + date;
lblTime.Text = "Time: " + time;
txtMessage.Text = dgvMessages.Rows[select].Cells[2].Value.ToString();
}
catch (NullReferenceException ex)
{
MessageBox.Show(ex.ToString());
}
}