Solved

problem setting a check box from cell leave

Posted on 2011-09-30
7
253 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 500 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

947 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now