Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to make Datagrid column to read only if checkbox is marked as closed

$
0
0

I want to set a column to read only/non-editable when a checkbox is marked as closed. I'm not sure how to do that.

Here is the code for the datagrid. I think it goes in the if (te.Closed) area of the code but not sure.

private void DgTimecards_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 15)
            {
                TimecardEntry te = dgTimecards.Rows[e.RowIndex].DataBoundItem as TimecardEntry;
                if (te.Closed)
                    return;
                ListBoxModal frm = new ListBoxModal("Select Other Reason", te.available_OTHERREASONS, te.curr_OTHERREASON);
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    te.curr_OTHERREASON = frm.SelectedItem as REFERENCE_OTHERREASON;
                    if (te.AltJobNum != "")
                    {
                        if (te.curr_OTHERREASON != null && te.prev_OTHERREASON != null &&
                                (te.curr_OTHERREASON.OTHERREASON_ALTJOBNUM != te.prev_OTHERREASON.OTHERREASON_ALTJOBNUM ||
                                    te.curr_OTHERREASON.OTHERREASON_CUSTOMER != te.prev_OTHERREASON.OTHERREASON_CUSTOMER))
                            te.mtc.ALTJOBNUM = "";
                    }
                    if (te.curr_OTHERREASON.OTHERREASON_ALTJOBNUM == 1 || te.curr_OTHERREASON.OTHERREASON_CUSTOMER == 1)
                    {
                        Cursor.Current = Cursors.WaitCursor;
                        SearchJobFrm altJobFrm = new SearchJobFrm(te.curr_OTHERREASON.OTHERREASON_CUSTOMER == 1 ? te.curr_OTHERREASON.OTHERREASON_CODE : "", lastSelectedJobNum);
                        if (altJobFrm.ShowDialog() == DialogResult.OK)
                            te.mtc.ALTJOBNUM = altJobFrm.SelectedJobNum;
                        else
                            return;
                        lastSelectedJobNum = altJobFrm.SelectedJobNum;
                    }
                    te.mtc.OTHERREASON = te.curr_OTHERREASON.VALUE;
                    te.prev_OTHERREASON = te.curr_OTHERREASON;
                    btnAltJob.Visible = te.curr_OTHERREASON == null ? false : (te.curr_OTHERREASON.OTHERREASON_ALTJOBNUM == 1 || te.curr_OTHERREASON.OTHERREASON_CUSTOMER == 1);
                    dc.SubmitChanges();
                    te.validateForEOD(true);
                    lblTC_Error.Visible = te.ErrorText != "";
                    lblTC_Error.Text = te.ErrorText;
                    dgTimecards.Rows[e.RowIndex].DefaultCellStyle.BackColor = te.ErrorText == "" ? Color.White : Color.LightPink;
                    dgTimecards.InvalidateRow(e.RowIndex);
                    PopulateEmployeeSummary();
                    CalculateTimecardTotals();
                }
            }
        }


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>