Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

problem setting a check box from cell leave

Posted on 2011-09-30
7
Medium Priority
?
274 Views
Last Modified: 2012-05-12
I am trying to set a check box value within a Data grid cell leave
event.  
Here is what I have coded, but it isn't working:
     void dgvPatientstoReview_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == -1) return;

           
            if (this.dgvPatientstoReview.Columns[e.ColumnIndex].Name == this.CreateAdj.Name)
            {
               
                DataRowView rowView = (DataRowView)this.m_srcBillingAudit.Current;
                string checkbox = this.dgvPatientstoReview.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString();
               
                if (checkbox.Equals("True".ToString()))
                {
                    if (string.IsNullOrEmpty(rowView["ClearReason"].ToString()))
                    {
                        MessageBox.Show("You must supply a reason in order to make an adjustment");
                        dgvPatientstoReview.Rows[e.RowIndex].Cells["CreateAdj"].Selected = false;
                        //((DataGridViewCheckBoxCell)dgvPatientstoReview.Rows[e.RowIndex].Cells["CreateAdj"]).Selected = false;
                        //((DataGridViewCheckBoxCell_dgvPatientstoReview.Rows[e.RowIndex].Cells[e.ColumnIndex]).Selected = false;
0
Comment
Question by:LenTompkins
  • 4
  • 3
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36893455
What if we try changing this:

if (checkbox.Equals("True".ToString()))

Open in new window


to this:

if (checkbox.Equals(bool.TrueString, StringComparison.InvariantCultureIgnoreCase))

Open in new window

0
 

Author Comment

by:LenTompkins
ID: 36893676
The test to look at checkbox = true works fine, when the user has not already submitted a reason
in ClearReason, I am trying to reset the check box back to false or not selected along with the
message.  That is what is not working.
Any thoughts?
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1500 total points
ID: 36894118
I believe this is what you are referring to. It's not specific to your code above, but hopefully it demonstrates what I think you are asking. Let me know otherwise  = )
private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
    DataGridView dgv = sender as DataGridView;

    if (dgv != null && dgv[e.ColumnIndex, e.RowIndex] is DataGridViewCheckBoxCell)
    {
        DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)dgv[e.ColumnIndex, e.RowIndex];

        cell.Value = false;
    }
}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:LenTompkins
ID: 36894379
Sorry it did not work either.  This grid contains two check boxes that are next to each other.  It made
me think that the next box which is not checked is getting the false value, but I just did another
test where both boxes are checked and it did not change the result of either one. Could the problem
be that this check box is not associated with a column in my table?  I'm going to try this next by adding
a column to the table and see if that changes the check box to false.  If you have any other ideas
on how to solve this, I'd like to hear.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36894982
Can you provide a screenshot of the form? Specifically, the check box area?
0
 

Author Comment

by:LenTompkins
ID: 36903293
Sorry I didn't respond over the weekend.  I tried a completely different way to solve this, and that
was worse, so here is a recap of the problem:
This is the screen print when I come into the form:
 
I also included the CellLeave code a
 Thank you , this has been driving me crazy.

 

Here is the code :
void dgvPatientstoReview_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == -1) return;

           
            if (this.dgvPatientstoReview.Columns[e.ColumnIndex].Name == this.CreateAdj.Name)
            {
               
                DataRowView rowView = (DataRowView)this.m_srcBillingAudit.Current;
                string checkbox = this.dgvPatientstoReview.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString();
               
                if (checkbox.Equals("True".ToString()))
                {
                    if (dgvPatientstoReview != null && dgvPatientstoReview[e.ColumnIndex, e.RowIndex] is DataGridViewCheckBoxCell)
                    {
                        DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)dgvPatientstoReview[e.ColumnIndex, e.RowIndex];

                        cell.Value = false;
                    }


                    if (string.IsNullOrEmpty(rowView["ClearReason"].ToString()))
                        MessageBox.Show("You must supply a reason in order to make an adjustment");

                    else
                    {
                        string differ = rowView["diff"].ToString();
                       
                        DialogResult result1 = MessageBox.Show(string.Format("An Adjustment of {0} days at Patient will be made.  Are you sure you want to do this? ",
                          differ), "Confirm Making Adjustments",
                          MessageBoxButtons.YesNo);
                        if (result1 == DialogResult.Yes)
                        {
                            m_BillingAdj.InsertBillingAuditAdjustment(rowView["MRN"].ToString(),
                                Convert.ToInt32(rowView["NO"].ToString()), Convert.ToInt32(differ), rowView["ClearReason"].ToString());
                            m_dtBillingAdj = m_BillingAdj.SelectBillingAuditAdjustments(rowView["MRN"].ToString(),
                                 Convert.ToInt32(rowView["NO"].ToString()));
                            m_srcBillingAdj.DataSource = m_dtBillingAdj;
                            dgvBillingAdjustments.DataSource = m_srcBillingAdj;
                            // update the BillingAudit table but we will not reselect records since that will clear this
                            // record and the user will not be able to review this change.
                            string delflag = this.dgvPatientstoReview.Rows[e.RowIndex].Cells["CPRFixed"].EditedFormattedValue.ToString();
                            if (delflag.Equals("True".ToString()))
                                cprFix = 1;
                            else
                                cprFix = 0;
                            int newDays = Convert.ToInt32(rowView["DaysAtPatient"].ToString()) + Convert.ToInt32(differ);
                            m_BillingAudit.UpdateBillingAudit(rowView["MRN"].ToString(), Convert.ToInt32(rowView["NO"].ToString()),
                                cprFix);
                           
                            dgvPatientstoReview.Rows[e.RowIndex].Cells["DaysAtPatient"].Value = newDays.ToString();
                            dgvPatientstoReview.Rows[e.RowIndex].Cells["Diff"].Value = "0".ToString();
                        }
                    }
                }

            }
            if (this.dgvPatientstoReview.Columns[e.ColumnIndex].Name == this.CPRFixed.Name)
            {
                string checkbox = this.dgvPatientstoReview.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString();

                if (checkbox.Equals("True".ToString()))
                    cprFix = 1;
                else
                    cprFix = 0;
                DataRowView rowView = (DataRowView)this.m_srcBillingAudit.Current;
                m_BillingAudit.UpdateBillingAudit(rowView["MRN"].ToString(), Convert.ToInt32(rowView["NO"].ToString()), cprFix);
            }
           
        }

Checkbox-problem.docx
0
 

Author Closing Comment

by:LenTompkins
ID: 36980211
Since I never got it to work the way you suggested, I performed the task a different way.  Thank you for your partial assistance.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question