I have a datagridview populated by the following code:
How do I allow hhe column hoursWorked to be editable? When I change column.ReadOnly to false, it fails.
Any help or insight would be grsatly appreciated.
Code:
if (hasTime == true)
{
string hourQuery = string.Format("SELECT contact.contactID, contact.firstName, contact.lastName, hours.hoursWorked" +
" FROM contact INNER JOIN hours ON contact.contactID=hours.contactID WHERE hours.fiscalYearID ={0}", selectedYearID.ToString());
cmd.CommandText = hourQuery;
cmd.Connection.Open();
var dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
DataTable cHours = new DataTable();
cHours.Load(dr);
bindings.DataSource = cHours;
dgvTime.DataSource = bindings;
cmd.Connection.Close();
}
foreach (DataGridViewColumn column in dgvTime.Columns)
{
if (column.HeaderText == "contactID") { column.HeaderText = "ID"; column.ReadOnly = true; column.Visible = false; column.Width = 50; }
if (column.HeaderText == "firstName") { column.HeaderText = "First"; column.Width = 150; column.ReadOnly = true; }
if (column.HeaderText == "lastName") { column.HeaderText = "Last"; column.Width = 150; column.ReadOnly = true; }
if (column.HeaderText == "hoursWorked") { column.HeaderText = "Annual Hours"; column.Width = 150; column.ReadOnly = true; }
}
Any help or insight would be grsatly appreciated.